BIG陽
2019-02-21 14:19:07
需求是這樣的:假設(shè)我有如下路由配置文件: { path: 'user', component: UserListComponent children: [ { path: ':id', component: UserDetailComponent } ] }一開始path為'/user', 渲染出所有的用戶(用戶列表), 然后點(diǎn)擊某一個(gè)用戶, 路由跳轉(zhuǎn)到'/user/2', 此時(shí)顯示id為2的用戶的詳細(xì)信息,但是這個(gè)時(shí)候用戶列表是應(yīng)該隱藏起來的。這樣的需求怎么實(shí)現(xiàn)?
2 回答

牧羊人nacy
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
UserDetailComponent 組件應(yīng)該和UserListComponent是同一級(jí),而不是他的子組件,共用同一個(gè)router-outlet。
路由應(yīng)該這么配置:
{
path: 'user',
component: UserListComponent
},
{ path: ':id',
component: UserDetailComponent
}

四季花海
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊
可以這樣,做一個(gè)無組件路由
{
path: 'user',
children: [
{
path: '',
component: UserListComponent
},
{
path: ':id',
component: UserDetailComponent
}
]
},
添加回答
舉報(bào)
0/150
提交
取消