Angular2+嵌套模块路由参数为空

Angular2+ nested module route params empty

我的应用层次结构如下:

  1. 应用程序(根)
    • Modules(模块)
      • 硕士
      • 详情
        • 导航
        • Create/home(分量)
        • 字段(模块)
          • 详细信息(组件)
          • 硕士(组件)

模块-routing.module.ts

const routes: Routes = [
 { path: 'modules-detail/:module_name', loadChildren: './module-detail/module-detail.module#ModuleDetailModule' },
 { path: '', component: ModulesMasterComponent }
];

模块详细信息-routing.module.ts

const routes: Routes = [
{
 path: '',
 component: ModulesNavComponent,
 children: [
    { path: '', component: CreateModuleComponent },
    { path: 'new', component: CreateModuleComponent },
    { path: 'fields', loadChildren: './fields/fields.module#FieldsModule' }
 ]
}
];

字段-routing.module.ts

const routes: Routes = [
{
  path: '',
  component: FieldsMasterComponent
},
{
  path: ':field_id',
  component: FieldDetailComponent
}
];

问题
当我重定向到 /modules/testModuleName/fields 时,我正在尝试访问我在模块中声明的 module_name 参数 - routing.module (testModuleName)。 但是,当我在字段模块中时,我的路由参数为空。 我能够在 create/home 组件中看到参数,但在子模块中看不到。如有任何帮助,我们将不胜感激!

您是如何访问参数的 如果您使用 router.params

然后切换成router.parent.params就可以得到id了。让我知道这是否适合你。