我有一个延迟加载模块,在此组件内默认为SuperUserComponent
我已经在4-5个子组件之间切换导航与ngSwitchCase。因为我在nativescript中使用它,所以我需要为整个路由模块提供一个单独的路由模块。
在我的主路由模块中,我有:
{
path: 'super-user',
loadChildren: './super-user/super-user.module#SuperUserModule',
pathMatch: 'full'
},
在模块自己的子路由模块中,我有:
const routes: Routes = [
{
path: ':resource',
component: SuperUserComponent,
pathMatch: 'full'
}
];
切换的切换如下:
<mat-button-toggle
[routerLink]="['/super-user', 'manage-users']"
value="manage-users"
>
Users
</mat-button-toggle>
在后端我每次加载主要组件时都会监听该参数:
this.paramSubscription = this.route.paramMap.subscribe(params => {
const newValue = params.get('resource');
this.superUserMenu = newValue;
});
如何在加载时配置子路由模块以匹配该参数?
做了一些研究,您只需要更改主路由模块
{
path: 'super-user',
loadChildren: './super-user/super-user.module#SuperUserModule',
pathMatch: 'prefix'
}
或者只是删除那行pathMatch: 'prefix'
,如果你不需要它。我认为你只是强迫角度来找到以“超级用户”结尾的路线,但是他很难做到这一点。