Gathering detailed insights and metrics for @uirouter/angular-hybrid
Gathering detailed insights and metrics for @uirouter/angular-hybrid
Gathering detailed insights and metrics for @uirouter/angular-hybrid
Gathering detailed insights and metrics for @uirouter/angular-hybrid
@uirouter/react-hybrid
### UI-Router support for Hybrid Angular/React apps
check-peer-dependencies
Checks peer dependencies of the current package. Offers solutions for any that are unmet.
@uirouter/angular
State-based routing for Angular
angular-ui-router
State-based routing for AngularJS 1.x
npm install @uirouter/angular-hybrid
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
167 Stars
669 Commits
75 Forks
12 Watching
21 Branches
22 Contributors
Updated on 11 Aug 2024
Minified
Minified + Gzipped
TypeScript (66.98%)
JavaScript (31.29%)
HTML (1.73%)
Cumulative downloads
Total Downloads
Last day
-19.4%
2,342
Compared to previous day
Last week
-1.8%
13,913
Compared to previous week
Last month
0.9%
59,651
Compared to previous month
Last year
-15.3%
659,893
Compared to previous year
1
This module provides ngUpgrade integration with UI-Router. It enables UI-Router to route to both AngularJS components (and/or templates) and Angular components.
Your app will be hosted by AngularJS while you incrementally upgrade it to Angular.
With @uirouter/angular-hybrid
you can use either an Angular component or an AngularJS component/template as the view in a state definition.
1import { Ng2AboutComponentClass } from "./about.ng2.component"; 2 3/// ... 4 5$stateProvider.state({ 6 name: 'home', 7 url: '/home', 8 component: 'ng1HomeComponent' // AngularJS component or directive name 9}) 10 11.state({ 12 name: 'about', 13 url: '/about', 14 component: Ng2AboutComponentClass // Angular component class reference 15}); 16 17.state({ 18 name: 'other', 19 url: '/other', 20 template: '<h1>Other</h1>', // AngularJS template/controller 21 controller: function($scope) { /* do stuff */ } 22})
When routing to an Angular component, that component uses the standard
Angular directives (ui-view and uiSref) from @uirouter/angular
.
When routing to an AngularJS component or template, that component uses the standard
AngularJS directives (ui-view and ui-sref) from @uirouter/angularjs
.
See the hybrid sample app for a full example.
Remove angular-ui-router
(or @uirouter/angularjs
) from your AngularJS app's package.json and replace it with @uirouter/angular-hybrid
.
Add the @angular/*
dependencies.
dependencies: {
...
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/upgrade": "^6.0.0",
...
"@uirouter/angular-hybrid": "^6.0.0",
...
}
Remove any ng-app
attributes from your main HTML file.
We need to use manual AngularJS bootstrapping mode.
ui.router.upgrade
1let ng1module = angular.module('myApp', ['ui.router', 'ui.router.upgrade']);
BrowserModule
, UpgradeModule
, and a UIRouterUpgradeModule.forRoot()
module.providers
entry for any AngularJS services you want to expose to Angular.ngDoBootstrap
method which calls the UpgradeModule
's bootstrap
method.1export function getDialogService($injector) { 2 return $injector.get('DialogService'); 3} 4 5@NgModule({ 6 imports: [ 7 BrowserModule, 8 // Provide angular upgrade capabilities 9 UpgradeModule, 10 // Provides the @uirouter/angular directives and registers 11 // the future state for the lazy loaded contacts module 12 UIRouterUpgradeModule.forRoot({ states: [contactsFutureState] }), 13 ], 14 providers: [ 15 // Provide the SystemJsNgModuleLoader when using Angular lazy loading 16 { provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader }, 17 18 // Register some AngularJS services as Angular providers 19 { provide: 'DialogService', deps: ['$injector'], useFactory: getDialogService }, 20 { provide: 'Contacts', deps: ['$injector'], useFactory: getContactsService }, 21 ] 22}) 23export class SampleAppModuleAngular { 24 constructor(private upgrade: UpgradeModule) { } 25 26 ngDoBootstrap() { 27 this.upgrade.bootstrap(document.body, [sampleAppModuleAngularJS.name], { strictDi: true }); 28 } 29}
Tell UI-Router that it should wait until all bootstrapping is complete before doing the initial URL synchronization.
1ngmodule.config(['$urlServiceProvider', ($urlService: UrlService) => $urlService.deferIntercept()]);
bootstrapModule()
and tell UIRouter to synchronize the URL and listen for further URL changes
1platformBrowserDynamic() 2 .bootstrapModule(SampleAppModuleAngular) 3 .then((platformRef) => { 4 // Intialize the Angular Module 5 // get() the UIRouter instance from DI to initialize the router 6 const urlService: UrlService = platformRef.injector.get(UIRouter).urlService; 7 8 // Instruct UIRouter to listen to URL changes 9 function startUIRouter() { 10 urlService.listen(); 11 urlService.sync(); 12 } 13 14 platformRef.injector.get < NgZone > NgZone.run(startUIRouter); 15 });
Your existing AngularJS routes work the same as before.
var foo = {
name: 'foo',
url: '/foo',
component: 'fooComponent'
};
$stateProvider.state(foo);
var bar = {
name: 'foo.bar',
url: '/bar',
templateUrl: '/bar.html',
controller: 'BarController'
};
$stateProvider.state(bar);
Register states using either Angular or AngularJS code.
Use component:
in your state declaration.
var leaf = {
name: 'foo.bar.leaf',
url: '/leaf',
component: MyNg2CommponentClass
};
$stateProvider.state(leaf);
1@NgModule({ 2 imports: [ 3 UIRouterUpgradeModule.forChild({ 4 states: [featureState1, featureState2], 5 }), 6 ], 7 declarations: [FeatureComponent1, FeatureComponent2], 8}) 9export class MyFeatureModule {}
Add the feature module to the root NgModule imports
1@NgModule({ 2 imports: [BrowserModule, UIRouterUpgradeModule.forChild({ states }), MyFeatureModule], 3}) 4class SampleAppModule {}
We currently support routing either Angular (2+) or AngularJS (1.x) components into an AngularJS (1.x) ui-view
.
However, we do not support routing AngularJS (1.x) components into an Angular (2+) ui-view
.
If you create an Angular (2+) ui-view
, then any nested ui-view
must also be Angular (2+).
Because of this, apps should be migrated starting from leaf states/views and work up towards the root state/view.
Resolve blocks on state definitions are always injected using AngularJS style string injection tokens.
'$transition$'
, '$state'
, or 'currentUser'
.1resolve: {
2 roles: ($authService, currentUser) => $authService.fetchRoles(currentUser);
3}
Transition
object as the first argument.1 // In Angular, the first argument to a resolve is always the Transition object 2 // The resolver (usually) must be exported 3 export const rolesResolver = (transition) => { 4 const authService = transition.injector().get(AuthService); 5 const currentUser = transition.injector().get('currentUser'); 6 return authService.fetchRoles(currentUser); 7 } 8 9 ... 10 11 resolve: { 12 roles: rolesResolver 13 }
In UI-Router for Angular/AngularJS hybrid mode, all resolves are injected using AngularJS style.
If you need to inject Angular services by class, or need to use some other token-based injection such as an InjectionToken
,
access them by injecting the $transition$
object using string-based injection.
Then, use the Transition.injector()
API to access your services and values.
1import { AuthService, UserToken } from './auth.service'; 2 3// Notice that the `Transition` object is first injected 4// into the resolver using the '$transition$' string token 5export const rolesResolver = function ($transition$) { 6 // Get the AuthService using a class token 7 const authService: AuthService = transition.injector().get(AuthService); 8 9 // Get the user object using an InjectionToken 10 const user = transition.injector().get(UserToken); 11 12 return authService.fetchRoles(user).then((resp) => resp.roles); 13}; 14 15export const NG2_STATE = { 16 name: 'ng2state', 17 url: '/ng2state', 18 component: Ng2Component, 19 resolve: { 20 roles: rolesResolver, 21 }, 22};
When a state has an onEnter
, onExit
, or onRetain
, they are always injected (AngularJS style),
even if the state uses Angular 2+ components or is added to an UIRouterUpgradeModule
NgModule
.
1export function ng2StateOnEnter(transition: Transition, svc: MyService) { 2 console.log(transition.to().name + svc.getThing()); 3} 4ng2StateOnEnter.$inject = [Transition, 'MyService']; 5export const NG2_STATE = { 6 name: 'ng2state', 7 url: '/ng2state', 8 onEnter: ng2StateOnEnter, 9};
The minimal example of @uirouter/angular-hybrid
can be found here:
https://github.com/ui-router/angular-hybrid/tree/master/example
A minimal example can also be found on stackblitz: https://stackblitz.com/edit/ui-router-angular-hybrid
A large sample application example with lazy loaded modules can be found here: https://github.com/ui-router/sample-app-angular-hybrid
The same sample application can be live-edited using Angular CLI and StackBlitz here: https://stackblitz.com/github/ui-router/sample-app-angular-hybrid/tree/angular-cli
Version 2.0.0 of @uirouter/angular-hybrid
only supports UpgradeAdapter
, which works fine but is no longer in development.
Version 3.0.0+ of @uirouter/angular-hybrid
only supports UpgradeModule
from @angular/upgrade/static
, which is what the Angular team actively supports for hybrid mode.
Because we dropped support for UpgradeAdapter
, current users of @uirouter/angular-hybrid
2.x will have to switch to UpgradeModule
when upgrading to 3.x.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 3/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More