我有类似的东西:
const routes: Routes = [
{
path: ':path', component: SiteRoot, children: [
{ path: '', loadChildren: '../modules/maple/template.module#TemplateModule' }
]
}
];
我希望使用这个:path url动态匹配多个模块。每个模块都有自己的内部路由。
有什么办法可以实现吗?
我尝试使用ResolveComponentFactory的ViewContainerRef,但它不适用于仅模块组件。使用NgModuleFactoryLoader的事件,无法应用路由。
编辑,让一切都清楚:
我想要实现的是在同一路径路径上显示不同的模块。例如,用户可以在“主页”路径中看到用户仪表板,管理员也可以在“主页”路径中看到管理仪表板。
此功能由业务逻辑定义,因此,我无法将管理仪表板更改为其他URL
我认为您正在尝试错误地创建路由模块。无论如何,你应该写下你为什么需要这个。我会尽力回答。每个模块都应该有自己的路径,因此路由模块应该是严格且静态的。如果您尝试安全性,请使用警卫并隐藏菜单组件中的项目。
如果你需要这样的URL:“/ username1 / profile”,“/ username2 / profile”你可以简单地使用像你这样的代码,或者使用延迟加载。为父模块创建路由文件:
{ path: ':username', loadChildren: '../users/user.module#UserModule' }
为子模块创建路由文件:
{ path: '', loadChildren: 'UserComponent', children: [
{ path: '', redirectTo: 'profile' },
{ path: 'profile', component: ProfileComponent}
]
}
根据您的情况更新:
根据您的情况,您可以更改HTML文件。例如,在app.component.html中,如果您的代码是:
<div>
<router-outlet></router-outlet>
</div>
你可以改变它:
<div *ngIf="isLoggedIn | async">
<admin-panel></admin-panel>
</div>
<div *ngIf="(!isLoggedIn | async)">
<router-outlet></router-outlet>
</div>