首页 > 解决方案 > 在延迟加载的子模块中带有参数的角度路由?无法匹配每次抛出的任何路由

问题描述

我有一个延迟加载的模块,默认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'
  }
];

切换酶的切换如下:

   <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;
    });

加载时如何配置该子路由模块以匹配该参数?

标签: angularangular-routingangular7angular-module

解决方案


做了一些研究,你只需要改变你的主路由模块

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

pathMatch: 'prefix'或者如果您不需要,只需删除该行。我认为您只是强迫 Angular 找到以“超级用户”结尾的路线,但他显然不能这样做。


推荐阅读