简体   繁体   English

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

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

I have a lazy loaded module which defaults to SuperUserComponent inside this component I have toggle navigation with ngSwitchCase between 4-5 child components. 我有一个延迟加载的模块,默认情况下该组件内部为SuperUserComponent我在4-5个子组件之间使用ngSwitchCase切换了导航。 Because I'm using this with nativescript I need to have a separate routing module for this whole routing module. 因为我将其与nativescript一起使用,所以需要为整个路由模块使用一个单独的路由模块。

Inside my main routing module I have: 在我的主要路由模块中,我具有:

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

Inside the module's own child routing module I have: 在模块自己的子路由模块中,我具有:

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

The toggles for the switchase is as follows: 切换酶的切换如下:

   <mat-button-toggle
        [routerLink]="['/super-user', 'manage-users']"
        value="manage-users"
      >
        Users
      </mat-button-toggle>

And on the backend I listen for that parameter every time I load the main component: 在后端,每次加载主要组件时,我都会监听该参数:

this.paramSubscription = this.route.paramMap.subscribe(params => {
      const newValue = params.get('resource');
      this.superUserMenu = newValue;
    });

How can I configure that child routing module to match that parameter when loading? 如何在加载时配置该子路由模块以匹配该参数?

Made some research, all you need is to change your mai nrouting module 做了一些研究,您所需要的只是更改您的网络模块

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

or just remove that line pathMatch: 'prefix' if you don't need that. 或仅删除该行pathMatch: 'prefix'如果不需要)。 I think you just forcing angular to find route that ends with 'super-user', but he, obiously, can't do that. 我认为您只是强迫角度去寻找以“超级用户”结尾的路线,但是他实在是做不到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM