在我们的主要 app.component 路由中,我们有这个:
{ path: 'store', loadChildren: './store/store.module#StoreModule', canActivate: [LoginGuard] },
然后在模块中我们有这样的路由:
const routes: Routes = [
{ path: '', component: StoreStartPageComponent},
{
path: ':name/:id', component: CategoryPageComponent,
children: [
{
path: ':childName/:childId', component: CategorySubPageComponent,
children: [
{ path: ':childName/:childId', component: CategorySubSubPageComponent }
]
}
]
},
{ path: '**', component: PageNotFoundComponent }
];
现在我需要的是让 param['id'] 像:
this.route.params
.switchMap((params: Params) => params['id'])
.subscribe(id => console.log('id', id));
奇怪的是,这只适用于 path: ':name/:id' 而不是它的孩子。我错过了什么?