【问题标题】:Angular2+ nested module route params emptyAngular2+嵌套模块路由参数为空
【发布时间】:2018-09-10 21:34:21
【问题描述】:

我的应用层次结构如下:

  1. 应用程序(根)
    • 模块(模块)
      • 大师
      • 详情
        • 导航
        • 创建/主页(组件)
        • 字段(模块)
          • 详细信息(组件)
          • 主(组件)

modules-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

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

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

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

【问题讨论】:

    标签: angular angular6 angular-routing ng-modules


    【解决方案1】:

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

    然后切换到router.parent.params,它就会得到id。让我知道这是否适合你。

    【讨论】:

    • 从 ActivatedRoute 访问参数后,我能够在 route.parent.parent.params 下找到它作为祖父路由。谢谢!
    猜你喜欢
    • 2016-08-21
    • 2017-04-22
    • 2017-01-22
    • 2019-08-04
    • 1970-01-01
    • 2017-02-15
    • 2017-12-03
    • 1970-01-01
    • 2016-07-28
    相关资源
    最近更新 更多