Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - Is it possible to use the new router while upgrading with the "Upgrade Adapter"

I am upgrading my application progressively using the Upgrade Adapter. My app uses ui-router (+ has child routes).

I read this great article about routing in Angular 2. My question is:

Is it possible to use new router while still in Angular 1.X app + Upgrade adapter?

For example:

I have an angular 1.X template with <div ui-view=""></div>. When I upgrade it to be Angular 2.0 component I must use the new component router with it, because Angular 2.0 is rendering this component now. But, in order to use it I should do:

bootstrap(App, [provide(LocationStrategy, { useClass: PathLocationStrategy })])

Which I do not have when bootstraping with the Upgrade Adater!

Should I first move the bootstrap to be Angular 2 and only then move to the Component router?

Thanks

like image 430
Yaniv Efraim Avatar asked Jan 26 '16 21:01

Yaniv Efraim


People also ask

Can be more than one router outlet element in Angular application?

Yes you can as said by @tomer above. i want to add some point to @tomer answer. firstly you need to provide name to the router-outlet where you want to load the second routing view in your view.

What module Do you need to add for using Angular router?

Import RouterModule from @angular/router link To add this functionality to your sample application, you need to update the app. module. ts file to use the module, RouterModule . You import this module from @angular/router .

How do I change the URL in an Angular application without reloading the route?

You could use location.go(url) which will basically change your url, without change in route of application.


1 Answers

Absolutely! Your component containing ui-view should be changed to a router-outlet, but otherwise, you should be able to convert your routes to AngularJS components and use them with the new RouterModule.

like image 65
wilsonhobbs Avatar answered Sep 21 '22 18:09

wilsonhobbs