简体   繁体   English

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

[英]Angular2+ nested module route params empty

My app hierarchy is as follows: 我的应用程序层次结构如下:

  1. app(root) 应用程序(根)
    • Modules (module) 模块(模块)
      • Master
      • Detail 详情
        • Nav 导航
        • Create/home (component) 创建/主页(组件)
        • Fields (module) 字段(模块)
          • Detail (component) 细节(组成部分)
          • Master (component) 硕士(组成部分)

modules-routing.module.ts 模块-routing.module.ts

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

modules-detail-routing.module.ts 模块细节-routing.module.ts

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

fields-routing.module.ts 场,routing.module.ts

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

Problem 问题
When i redirect to /modules/testModuleName/fields, I am trying to access my module_name param thats declared in the modules-routing.module (testModuleName). 当我重定向到/ modules / testModuleName / fields时,我试图访问在modules-routing.module(testModuleName)中声明的module_name参数。 However, my route params come up empty when i am in the fields module. 但是,当我在fields模块中时,我的路线参数显示为空。 I am able to see the param in the create/home component, but not in the child modules. 我可以在create / home组件中看到该参数,但在子模块中看不到。 Any help would be appreciated! 任何帮助,将不胜感激!

How are you accessing the Param If you are using router.params 如果使用router.params,如何访问参数

Then switch it to router.parent.params and it will get the id. 然后将其切换到router.parent.params,它将获得ID。 Let me know if that works for you. 让我知道这是否适合您。

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

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