我是 Angular 2 的新手,实际上我在刷新其重定向到登录页面时遇到了问题,但实际上我想重定向到仪表板
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
// get observable
const observable = this.store.select(isAuthenticated);
// redirect to sign in page if user is not authenticated
observable.subscribe(authenticated => {
if (!authenticated) {
this.router.navigate(['/login']);
}
});
return observable;
}
路由模块:
const routes: Routes = [
{
canActivate: [AuthGuard],
path: "dashboard",
loadChildren: "./dashboard/dashboard.module#DashboardModule"
},
{
path: "",
pathMatch: "full",
redirectTo: "dashboard"
}
];