What are the benefits and disadvantages of using ui-router-ng2 instead of the new Angular2 router? In the past i used ui-router with Angular 1.x instead of using ngRoute, because i need better support for nested states/routes.
So now, what about Angular2? I would like to hear by you so i can evaluate both opportunities.
Besides, searching and searching on Google i found ngrx/router, that i didn't know. Can you tell me what are the differences between the builtin router of Angular2, the new ui-router for Angular2 and ngrx router?
The ui-router is effective for the larger application because it allows nested-views and multiple named-views, it helps to inherit pages from other sections. In the ngRoute have to change all the links manually that will be time-consuming for the larger applications, but smaller application nrRoute will perform faster.
UI-Router is the defacto standard for routing in AngularJS. Influenced by the core angular router $route and the Ember Router, UI-Router has become the standard choice for routing non-trivial apps in AngularJS (1. x).
NGRX Router docs
ngrx router is Deprecated! There is migration strategy from ngrx router to the standard Angular2 Router.
Angular2 Router docs
Angular2 Router has almost all UI-router features.
NG2 UI-router docs
Well known UI-router from AngularJS updated for the Angular2. From the known advantages - makes smoother update from AngularJS UI-router to ng2 UI-router.
Let's compare syntax of UI-router both versions with Angular2 Router.
AngularJS UI-router :
app.config(function($stateProvider){ $stateProvider.state('home', { url: '/home', templateUrl: 'home.html', controller: 'HomeCtrl' }) });
Angular2 UI-router :
export let state1: Ng2StateDeclaration = { name: 'home', component: HomeComponent, url: '/home' } @NgModule({ imports: [ SharedModule, UIRouterModule.forChild({ states: [home] }) ], declarations: [HomeComponent] }) export class MyModule {}
Angular2 Router :
(Update: property - name
was removed after V3-alpha7. Because it didn't work out with lazy loading of routes.)
import { RouteConfig, Route } from 'angular2/router'; import {HomeComponent} from './components/home'; @Component({}) @RouteConfig([ new Route({ path: '/home', component: HomeComponent, name: 'Home' // Deprecated property, works until v3-alpha7 }) ]) export class App {...}
As we can see, in general, Angular2 Router is pretty much the same. As addition need to say that it support most of the common features like static/dynamic data sharing through the routes, nested views etc.
Angular2 Router had taken best of UI-router experience and implemented it. If you need easy migrate your code base with AngularJS UI-router to Angular2 fast and smoothly, you can try Ng2 UI-router, otherwise, I think Angular2 Router will fit best. Even if you decided to use NG2 UI-router, check all pros and cons, at current point I feel like the community is going to choose a standard solution from the Angular team which means better support.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With