使用多子时如何使用routerLink?
how to use routerLink when using multi children?
这是 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]"
但我得到另一个 URL 之类的东西
http://localhost:3000/adminHome/users/%3Aid/58e35bdeaf314301ec86c249
你的link是错误的。使用 [routerLink]
时,您不需要指定 :id
,就像您不需要使用路径变量那样,它被定义为放置 id 的占位符。
[routerLink]
应如下所示:
[routerLink]="['/adminHome/users', x.id]"
编辑
为了构建具有更多参数的 [routerLink]
,请执行以下操作:
[routerLink]="['/adminHome/users', param1, param2...]"
这将导致:/adminHome/users/1/2
如果 param1=1
和 param2=2
这是 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]"
但我得到另一个 URL 之类的东西
http://localhost:3000/adminHome/users/%3Aid/58e35bdeaf314301ec86c249
你的link是错误的。使用 [routerLink]
时,您不需要指定 :id
,就像您不需要使用路径变量那样,它被定义为放置 id 的占位符。
[routerLink]
应如下所示:
[routerLink]="['/adminHome/users', x.id]"
编辑
为了构建具有更多参数的 [routerLink]
,请执行以下操作:
[routerLink]="['/adminHome/users', param1, param2...]"
这将导致:/adminHome/users/1/2
如果 param1=1
和 param2=2