这是 AdminRouting
path: 'adminHome',
component: adminHomeComponent,
children: [
{
path: '',
component: HomeComponent,
},
{
path: 'home',
component: HomeComponent,
},
{
path: 'users',
component: UserListComponent,
children: [
{
path: '',
component: HUComponent
},
{
path: ':id',
component: EntrepriseListComponent,
children: [
{
path: '',
component: HyComponent
},
{
path: ':id',
component: ListLaucauxComponent
},
]
}
]
},
]
},
我想获取 List LocauxComponent 通过单击企业 ID 以获取此 URL localhost:3000/adminHome/users/{{id_user}}/{{id_entreprise}}
我试试
[routerLink]="['/adminHome/users/:id',x.id]"
但我得到另一个类似的网址
http://localhost:3000/adminHome/users/%3Aid/58e35bdeaf314301ec86c249
最佳答案
您的链接有误。使用 [routerLink]
时,您不需要指定 :id
,就像您不需要使用路径变量那样,它被定义为占位符放置 id。
[routerLink]
应该如下所示:
[routerLink]="['/adminHome/users', x.id]"
编辑
为了构建具有更多参数的[routerLink]
,请执行以下操作:
[routerLink]="['/adminHome/users', param1, param2...]"
这将导致:/adminHome/users/1/2
如果 param1=1
和 param2=2
关于angular - 使用多子时如何使用routerLink?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43203848/