【发布时间】:2021-02-17 00:46:18
【问题描述】:
我的 Angular 项目中有以下路由配置:
export const routes: Routes = [
{ path: 'a/:id', loadChildren: './a/a.module#AModule', data: {a: a}},
{ path: 'b/:id', loadChildren: './b/b.module#BModule', data: {a: b}}
];
现在我可以像这样得到我的路由配置:
this.router.config //outputs the above array
this.router.url 显示a,但我如何正确识别正确的Route,因为配置具有未解析的路径,而路由器拥有已解析的路径。
我想这样做的原因是访问app.component 中的data,其中我的router-outlet 不在组件本身中(角度文档说data 对象只能访问路由组件本身。
【问题讨论】: