我使用PathLocationStrategy与Angular2 rc.4(路由器3.0.0-beta.2)。Angular2:成功登录和注销得到重定向到本地主机:3000 /#
我遇到了touter重定向的奇怪问题。
案例1:首先要清除浏览器历史记录/缓存文件
从localhost:3000/login
登录成功后,路由器会重定向到localhost:3000
,这是符合市场预期。
注销后,路由器首先重定向到localhost:3000/#
,然后重定向到localhost:3000/login
。
案例2:与病例1
的历史成功登录后从localhost:3000/login
,路由器重定向到localhost:3000/#
。
注销后,路由器首先重定向到localhost:3000/#
,然后重定向到localhost:3000/login
。
我的问题是为什么localhost:3000/#
出现在上述情况下,我该如何摆脱它们。
我的路线设置为
export const LoginRoutes = [
{
path: '',
redirectTo: '/myapp/dashboard',
pathMatch: 'full'
},
{ path: 'login',
component: LoginComponent
}
];
和
export const ProtectedRoutes: RouterConfig = [
{
path: '',
redirectTo: '/myapp',
pathMatch: 'full'
},
{
path: 'myapp',
component: RouteDispatcherComponent,
canActivate: [AuthGuard],
children: [
{
path: '',
redirectTo: '/myapp/dashboard',
pathMatch: 'full'
},
{
path: 'dashboard',
component: DashboardComponent
}
]
}
]
在我登录组件,我用this.router.navigate(['/myapp/dashboard']);
浏览到我的仪表板页面。
而且AuthGuard
就像
canActivate() {
if (this.authService.isAuthenticated()) {
return true;
}
this.router.navigate(['/login']);
return false;
}
顺便说一句,这件事发生在一个以上的浏览器(Chrome,Firefox和Safari)。