What is equivalent to state parameters (Angular 1 & ui-router) in Angular 2?

In Angular 1 and ui-router, I used state parameters to transfer data from one state to another (without using URL parameters). Is this possible in Angular 2?

The router, RouteParams, RouterLink and RouteData do not seem to handle this, for example, I want to transfer a user object from one state to another

<a ui-sref="home({user: myCtrl.user})"> 

this is not possible in Angular 2.

+5
source share
1 answer

If you use an Angular 2 router, you can pass state through @RouteParams , for example,

 <a [routerLink]="['/ProductDetail', {id: 1234}]">Product Details</a> 

In this case, id is your state, and it can be any object, for example:

 <a [routerLink]="['/ProductDetail', myStateObject]">Product Details</a> 

Angular 2, on the other hand, has a mechanism for passing parameters using the parameter binding of the @Input() component, but this can only be used within the same route.

-1
source

Source: https://habr.com/ru/post/1239200/


All Articles