您好我配置了此路由:
const routes: Routes = [
{
path: '',
component: LayoutComponent,
canActivateChild: [AuthGuardService],
children: [
{
path: '',
pathMatch: 'full',
redirectTo: '/buchbestellungen',
canActivate: [AuthGuardService]
},
{
path: 'buchbestellungen',
component: BuchbestellungenComponent,
canActivate: [AuthGuardService]
},
{
path: 'buchbestellungen2',
component: Buchbestellungen2Component,
canActivate: [AuthGuardService]
},
]
},
{path: 'login', component: LoginComponent},
{path: '**', component: NotFoundComponent}
];
我不想要处理登录页面的名称,如果这是将来退出后的目标页面。因此,在注销完成后,logout组件将重定向到startpage。
目前,它不是起始组件(后来可能有一个仪表板),而是重定向到" buchbestellungen"路由,如果您通过身份验证如果您尚未登录,则访问起始页面会重定向到/ buchbestellungen,并且auth-guard服务会重定向到登录路由。
这适用于每条路线(例如buchbestellungen2),但不是,当我在/ buchbestellungen时退出时。这会重定向到" /"然后回到buchbestellungen。但是没有调用auth-guard(我在canActivate()方法中有一个Console.log(),但它也没有被调用)。
示例1: buchbestellungen2 - > logout() - >重定向到/ - >重定向到/ buchbestellungen由auth-guard拦截我在/ login route上结束
示例2: buchbestellungen - > logout() - >重定向到/ - >重定向到/ buchbestellungen(没有auth-guard,也没有重定向到/ login)
是否有可能,路由器不会调用auth-guard,因为我来自/ buchbestellungen这个溃败已经过验证了?是否有可能强制路由器调用警卫?
由于
答案 0 :(得分:0)
如果路线没有改变(并且重定向不计入路线变化),默认情况下Angular会重新使用分量。除了实现自定义RouteReuseStrategy(这看起来像是一种过度杀伤)之外,我唯一的想法就是创建一种附加到/ logout路径的LogoutComponent。该组件会在ngOnInit期间将用户重定向回root,或者可以由AuthGuard保护,它将执行重定向。