Angular Router - 带 id 的嵌套子级

问题描述 投票:0回答:3

我的角度路由器的一部分看起来像这样:

{
  path: 'things',
  component: ThingsComponent,
  children: [
    {
      path: ':id',
      component: ThingDetailComponent
    }
  ]
}

当点击

localhost:4200/things/3
时,为什么它落在
ThingsComponent
而不是
ThingDetailComponent

angular angular-router
3个回答
0
投票

除了指定详细路由作为子项,你还可以像这样进行路由:

{
    path: 'things',
    component: ThingComponent,
  },
  {
    path: 'things/:id',
    component: ThingDetailComponent
  }
}

0
投票

您只需将

path: ':id'
替换为
path: 'things/:id'
即可完成。


0
投票

像这样:

{
  path: 'things', 
  children: [
  {
    path: '',
    component: ThingsComponent,
  },

  {
    path: ':id',
    component: ThingDetailComponent
  }
 ]
}
© www.soinside.com 2019 - 2024. All rights reserved.