在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ Angular4 - 子路由觸發(fā)時隱藏父路由的組件

Angular4 - 子路由觸發(fā)時隱藏父路由的組件

需求是這樣的:

假設我有如下路由配置文件:

  {
    path: 'user',
    component: UserListComponent
    children: [
      {
        path: ':id',
        component: UserDetailComponent
      }
    ]
  }

一開始path為'/user', 渲染出所有的用戶(用戶列表), 然后點擊某一個用戶, 路由跳轉(zhuǎn)到'/user/2', 此時顯示id為2的用戶的詳細信息,但是這個時候用戶列表是應該隱藏起來的。

這樣的需求怎么實現(xiàn)?

回答
編輯回答
拮據(jù)

UserDetailComponent 組件應該和UserListComponent是同一級,而不是他的子組件,共用同一個router-outlet。
路由應該這么配置:

{
    path: 'user',
    component: UserListComponent
},
   
{    path: ':id',
     component: UserDetailComponent 
 }
2017年7月20日 13:41
編輯回答
久舊酒

user組件加個插座outlet

2018年3月17日 09:04
編輯回答
舊城人

可以這樣,做一個無組件路由
{

    path: 'user',
    children: [
        {
            path: '',
            component: UserListComponent
        },
        {
            path: ':id',
            component: UserDetailComponent 
        }
    ]
},
2018年4月7日 08:34