嗨,我已经设置了我的路线文件
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
最佳答案
为此,您需要从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 }
];