Angular 8两个子路径均指向同一组件

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

我有如下所示的父根

const routes: Routes = [
  {
    path: 'parent',
    component: ParentComponent,
    children: CHILD_TAB_ROUTES,
  },
]


Than i have child tabs as following

export const CHILD_TAB_ROUTES: Routes = [
  { path: '', redirectTo: 'childA', pathMatch: 'full' },
  {
    path: 'childA',
    component: ModelAComponent,
  },
  {
    path: 'childB',
    component: ModelBComponent,
  },
  { path: 'childC', component: ModelCComponent },
];

所以有3条路线,例如跟随路线,当用户默认情况下单击父级时,将其呈现为childA

parent/childA
parent/childB
parent/childC

现在我想拥有一条类似的路线,我希望拥有相同的组件ModelAComponent

parent/childA/:id

[考虑到它具有不同的路线,如何使parent/childA/:id转到ModelAComponent

angular angular-router
1个回答
0
投票
您将其添加为同一级别的孩子的另一条路线。

export const CHILD_TAB_ROUTES: Routes = [ { path: '', redirectTo: 'childA', pathMatch: 'full' }, { path: 'childA/:id', component: ModelAComponent, }, { path: 'childA', component: ModelAComponent, }, .... ];

© www.soinside.com 2019 - 2024. All rights reserved.