Wednesday, July 17, 2019

Passing multiple parameters in an Angular Route using RouteLink

In Angular, let’s say you have a route defined like this.

{ path : 'user/:userId/building/:buildingid, component: UserScheduleDetailsComponent, pathMatch : 'full'}

and you want to navigate the user to this component by using this route. I couldn’t easily find a way to pass these parameters by using routelink.

So this is how you do it.

<a [routerLink]="[ '/user/', userId, 'building', buildingId]">I am a link</a>

The userid is public property in the .ts file of the controller. There is just one gotcha. In the middle, there are these hard coded strings, for eg. building, do not put ‘/’ in the beginning or at the end of ‘building’. Only the first part of this route can have ‘/’ in it.

No comments:

Post a Comment