How to pass a parameter to routerLink that is some

2019-01-30 09:39发布

I know I can pass a parameter to routerLink for routes such as

/user/:id

by writing

[routerLink]="['/user', user.id]"

but what about routes such as this one:

/user/:id/details

Is there a way to set this parameter or should I consider a different URL scheme?

2条回答
爷的心禁止访问
2楼-- · 2019-01-30 09:58

Maybe it is really late answer but if you want to navigate another page with param you can,

[routerLink]="['/user', user.id, 'details']"

also you shouldn't forget about routing config like ,

 [path: 'user/:id/details', component:userComponent, pathMatch: 'full']
查看更多
Luminary・发光体
3楼-- · 2019-01-30 10:02

In your particular example you'd do the following routerLink:

[routerLink]="['user', user.id, 'details']"

To do so in a controller, you can inject Router and use:

router.navigate(['user', user.id, 'details']);

More info in the Angular docs Link Parameters Array section of Routing & Navigation

查看更多
登录 后发表回答