角度6:如何在其父级插座中显示组件?

时间:2018-08-20 23:27:50

标签: angular typescript router-outlet

是否可以在其父级的路由器出口中显示组件?这些是我的路线:

{
path: 'myHotels', component: MyHotelsParentComponent,
resolve: {myHotels: MyHotelsResolver},
children: [
  {path: '', component: MyHotelsComponent},
  {
    path: ':hotelId', component: MyHotelComponent,
    resolve: {myHotel: MyHotelResolver, categories: CategoriesResolver},
    children: [
      {path: '', component: MyRoomsComponent},
      {path: 'rooms/:roomId', component: MyRoomComponent, resolve: {myRoom: MyRoomResolver}},
    ]
  },
]},

我想在与MyHotelsComponent和MyHotelComponent相同的路由器插座上显示MyRoomComponent。我也想保留我的解析数据来自父路由。

1 个答案:

答案 0 :(得分:0)

您可以拥有

   {path:'',
    children:[
      {path:'rooms/room'...},
      {path:':hotelId'...}
    ]
   }

看到必须在“:hotelId”之前放置“ rooms / room”,第一个路由器Angular会找到第一个服务组件