我使用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)。