[英]Child routes depended on a condition in Angular 8
如何根据条件在子路由中加载组件? 我的路线:
const mainRoutes: Routes = [
{
path: '',
component: MainComponent,
canActivate: [AuthGuard],
children: [
...
{
path: 'dashboard',
component: DashboardComponent,
children: [
if(isUser) { // <= this is an example that I want to do
return {
path: '',
component: UserComponent, // if user is login in it should load this component
}
} else {
return {
path: '',
component: NotUserComponent, // if no user it should load this component
}
}
],
}
}
@NgModule({
imports: [RouterModule.forChild(mainRoutes)],
exports: [RouterModule],
})
export class MainRoutingModule {}
第二个问题:可以在路由器模块中注入授权服务并根据用户登录建立路由吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.