您好我的路线文件设置如下
const routes: Routes = [
{ path: '', component: parentComponent, canActivate: [ LoggedInGuard ], children: [
{ path: 'profile', component: ProfileComponent },
{ path: 'sign-out', component: SignOutComponent },
{ path: 'set-password', component: SetPasswordComponent },
{ path: '', canActivate: [ LastLoginDateGuard ], children: [
{ path: 'admin', canActivate: [ adminGuard ], children: [
{ path: 'event/:event_id', component: appComponent, children: [
{ path: '', component: EventComponent }
]},
]},
]},
{ path: '', redirectTo: '/sign-in', pathMatch: 'full' },
]},
{ path: '', component: AppComponent },
{ path: 'home', component: HomeComponent },
{ path: 'sign-in', component: SignInComponent },
{ path: 'sign-up', component: SignUpComponent },
{ path: '**', component: PageNotFoundComponent }
];

我需要的是event/:event_id
路线与正常parentComponent
{ path: 'admin', canActivate: [ adminGuard ], children: [
{ path: 'event/:event_id', component: appComponent, children: [
{ path: '', component: EventComponent }
]},
]},

我基本上只希望event/:event_id
的父组件appComponent
而不是parentCompnent
答案 0 :(得分:2)
为此你需要从ParentComponent
孩子中移除整个路线部分,并使用AppComponent
的父母制作另一个,
请尝试此路线设置:
const routes: Routes = [
{ path: '', component: parentComponent, canActivate: [ LoggedInGuard ], children: [
{ path: 'profile', component: ProfileComponent },
{ path: 'sign-out', component: SignOutComponent },
{ path: 'set-password', component: SetPasswordComponent },
{ path: '', redirectTo: '/sign-in', pathMatch: 'full' }
]},
{ path: '', canActivate: [ LoggedInGuard ], children: [
{ path: '', canActivate: [ LastLoginDateGuard ], children: [
{ path: 'admin', component: appComponent, canActivate: [ adminGuard ], children: [
{ path: 'event/:event_id' , children: [
{ path: '', component: EventComponent }
]},
]},
]}
]},
{ path: '', component: AppComponent },
{ path: 'home', component: HomeComponent },
{ path: 'sign-in', component: SignInComponent },
{ path: 'sign-up', component: SignUpComponent },
{ path: '**', component: PageNotFoundComponent }
];