我通常做的是为应用程序的授权部分创建一个父路由,并在其上设置路由保护.事实上,这条路线<router-outlet></router-outlet>在其模板内部只有基本组件,但在该路线上击中路线保护之前,无法访问子路线.请参阅下面的示例.
const routes: Routes = [
{ path: '', redirectTo: 'app/books', pathMatch: 'full' },
{ path: 'app', component: MainComponent, canActivate: [AuthGuard], children: [
{path: 'books', component: BooksComponent },
{path: 'cars', component: CarsComponent },
{path: 'trees', component: TreesComponent }
]},
{ path: 'login', component: LoginComponent, canActivate: [NonauthGuard] }
];
Run Code Online (Sandbox Code Playgroud)
NonAuthGuard 在我的情况下提供相反的行为,并且不允许用户在授权时点击登录路线.
| 归档时间: |
|
| 查看次数: |
1136 次 |
| 最近记录: |