我需要从1个解析监护人访问另一个父母(从父母到孩子),其中“另一个”(孩子)具有异步数据,因此我如何从子路由到父路由获取此异步数据
这是一些代码
路径
const routes: Route[] = [
{ path: '', redirectTo: 'main', pathMatch: 'full' },
{ path: 'main', component: MainComponent },
{ path: 'project',
component: ProjectContainerComponent,
children: [
{
path: ':id',
component: ProjectComponent,
data: {
projectTitle: 'Все задачи',
groupBy: 'Без группировки'
},
resolve: {
projectName: ProjectNameResolverService
},
children: [
{ path: '', redirectTo: 'list', pathMatch: 'full'},
{ path: 'list', component: ProjectIssueListContainerComponent, children: [
{ path: '', component: ProjectIssueListComponent },
{ path: ':issueId', component: ProjectIssueContainerComponent,
resolve: {
task: IssueResolverService
}
}
] },
{ path: 'create', component: CreateIssueComponent },
]
}
]
},
{ path: 'access_denied', component: AccessDeniedComponent }
]
孩子
export class IssueResolverService implements Resolve < any > {
constructor(
private projectsService: ProjectsService,
private router: Router
) {}
resolve(route: ActivatedRouteSnapshot) {
const id = +route.paramMap.get('issueId');
return this.projectsService.getProjectTask(id)
.pipe(
map((task: any) => {
console.log(task);
return task
})
);
}
}
父母
export class ProjectNameResolverService {
constructor() { }
resolve(route: ActivatedRouteSnapshot) {
console.log(route.firstChild.firstChild.data) // {} - but need to get it
}
}