Angular 在子延迟加载模块中使用参数进行路由?无法匹配每次抛出的任何路线

Angular routing with parameters in a child, lazy-loaded module? Can't match any routes thrown every time

我有一个惰性加载模块,默认为 SuperUserComponent 在此组件内 我使用 ngSwitchCase 在 4-5 个子组件之间切换导航。因为我将它与 nativescript 一起使用,所以我需要为整个路由模块提供一个单独的路由模块。

在我的主要路由模块中,我有:

 {
    path: 'super-user',
    loadChildren: './super-user/super-user.module#SuperUserModule',
    pathMatch: 'full'
  },

在模块自己的子路由模块中,我有:

const routes: Routes = [
  {
    path: ':resource',
    component: SuperUserComponent,
    pathMatch: 'full'
  }
];

switchase 的开关如下:

   <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'。我认为你只是强迫 angular 找到以 'super-user' 结尾的路线,但他显然不能那样做。