对于 Angular2 Router3,为什么每次在 child 路由之间切换时我的 Parent 路由守卫都没有被调用?
For Angular2 Router3, why isn't my Parent Route's Guard called every time I switch between its child routes?
我的 parent 路线有一个守卫,在查看 child 路线时并不总是被调用。它在加载第一个 child 时调用,但如果我在同一个 parent 中切换到另一个 child,则不会再次引用 parent 的 Guard。这是我拥有的:
export const AppRoutes: RouterConfig = [
{
path: 'app',
component: AppComponent,
canActivate: [LoggedInGuard],
children: [
{path: 'child1', component: Child1Component, canActivate: [AuthGuard]},
{path: 'child2', component: Child2Component, canActivate: [AuthGuard]},
{path: 'error/:status', component: ErrorComponent}
]
}
];
有没有办法确保每次在 child1 和 child2 之间切换时调用 LoggedInGuard?
canActivateChild: [LoggedInGuard]
到了,可以通过router的canActivateChild来实现。
我的 parent 路线有一个守卫,在查看 child 路线时并不总是被调用。它在加载第一个 child 时调用,但如果我在同一个 parent 中切换到另一个 child,则不会再次引用 parent 的 Guard。这是我拥有的:
export const AppRoutes: RouterConfig = [
{
path: 'app',
component: AppComponent,
canActivate: [LoggedInGuard],
children: [
{path: 'child1', component: Child1Component, canActivate: [AuthGuard]},
{path: 'child2', component: Child2Component, canActivate: [AuthGuard]},
{path: 'error/:status', component: ErrorComponent}
]
}
];
有没有办法确保每次在 child1 和 child2 之间切换时调用 LoggedInGuard?
canActivateChild: [LoggedInGuard]
到了,可以通过router的canActivateChild来实现。