我的应用层次结构如下:
- 应用(根( 模块
- (模块(
- 主人
- 细节
- 导航
- 创建/主页(组件(
- 字段(模块(
- 细节(组件(
- 主(组件(
- (模块(
modules-routeting.module.ts
const routes: Routes = [
{ path: 'modules-detail/:module_name', loadChildren: './module-detail/module-detail.module#ModuleDetailModule' },
{ path: '', component: ModulesMasterComponent }
];
modules-detail-routeting.module.ts
const routes: Routes = [
{
path: '',
component: ModulesNavComponent,
children: [
{ path: '', component: CreateModuleComponent },
{ path: 'new', component: CreateModuleComponent },
{ path: 'fields', loadChildren: './fields/fields.module#FieldsModule' }
]
}
];
fields-routeting.module.ts
const routes: Routes = [
{
path: '',
component: FieldsMasterComponent
},
{
path: ':field_id',
component: FieldDetailComponent
}
];
问题 当我重定向到/modules/testModuleName
/fields 时,我正在尝试访问在 modules-routing.module (testModuleName( 中声明的module_name参数。 但是,当我在字段模块中时,我的路由参数为空。 我能够在创建/主页组件中看到参数,但在子模块中看不到参数。任何帮助将不胜感激!
您如何访问参数 如果您使用的是 router.params
然后将其切换到router.parent.params,它将获得id。让我知道这是否适合您。