【发布时间】:2018-07-20 18:22:29
【问题描述】:
目前,在 Angular 中,您可以通过对其中一个父路由应用路由器保护来限制对所有子路由的访问:
export const routes: Routes = [
{
path: 'my-account',
canActivate: [IsUserLoggedIn],
children: [{
path: 'settings',
component: SettingsComponent
}, {
path: 'edit-profile',
component; EditProfileComponent
}]
}
];
这对于避免在每条路由中重复 canActivate 保护很有用。但是现在当我想在my-account 下引入第三条应该可以公开访问的路由时会发生什么?例如,my-account/help 可能有一个可公开访问的帮助页面,每个人都应该能够访问,即使他们没有登录:
}, {
path: 'help',
component: HelpComponent,
// Somehow make exception to canActivate guard above
}, {
是否有一种干净的方法可以做到这一点,或者是唯一的方法来破坏路由的组织并手动将路由器保护应用于每个子路由,帮助页面除外?
【问题讨论】:
标签: angular angular-router angular-router-guards