>我有以下路由配置。如何从项目编辑组件内部访问父路由中看到的:p rojectId?
{
path: 'folders/:folderId/projects/:projectId/s',
component: ProjectDetailComponent,
canActivate: [AuthGuardService],
children: [
{
path: 'edit',
component: ProjectEditComponent,
canActivate: [AuthGuardService],
},
{
path: 'i',
component: IssuesListComponent,
canActivate: [AuthGuardService],
},
],
},
我以前在没有子路由时使用这种方法:
this.activatedRoute.params.subscribe((urlParameters) => {
this.project_id = urlParameters['projectId'];
});
不幸的是,这不再有效。
您应该能够使用 Activated Route 父属性访问父路由参数:
this.activatedRoute.parent.params.subscribe((urlParameters) => {
this.project_id = urlParameters['projectId'];
});
您可以使用@Input提取父组件中的 projectId 并将其传递给两个子组件