1
ルートがAuthGuardによってブロックされている場合、私のホームページにリダイレクトする方法はありますか?角2 Auth Guardホームページにリダイレクト
たとえば、ログインしていない状態でwww.my-example.com/userにアクセスすると、ユーザーは認証ガードによってブロックされます。そのユーザーがホームページにリダイレクトされるようにします。現時点では空白のページしか表示されません。
// app.routing.ts
const APP_ROUTE: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full', },
{ path: '', component: UserLayoutComponent, children: [
{ path: 'user', loadChildren: 'app/user/user.module#CalenderModule' },
]
}];
// user.routing.ts
const USERR_ROUTE: Routes = [
{ path: '', component: UserComponent, canActivate: [AuthGuard] },
];
export const userRouting = RouterModule.forChild(USERR_ROUTE);
それはあなたを助ける:http://stackoverflow.com/documentation/angular2/1208/routing-3-0-0/7648/create-the-guard#t=201703151321281233562 – Faly
はい、それ可能だ。 AuthGuardの実装方法を示す郵便番号。 – Riv
問題が解決しました。簡単なthis.router.navigateが解決策でした。ありがとうございます – ErnieKev