我正在研究 Angular-6 项目。我的应用程序有很多子路由。其中之一如下:
const routes: Routes = [
{
path: 'innovation-track/:innovation-track-id', component: InnovationTrackComponent,
children: [
{
path: 'sprint', component: ScrumBoardComponent
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
我想从我的ScrumBoardComponent 中的URL获取创新轨道 ID值。
我知道我可以通过执行以下操作来做到这一点:
constructor(private _route: ActivatedRoute) { }
//somewhere in method
this._route.snapshot.parent.paramMap
Run Code Online (Sandbox Code Playgroud)
但是,我想在任何组件中获取创新轨道 ID值,无论它是子组件还是父组件都没有关系。我的意思是我不想做以下事情:
this._route.snapshot.parent.paramMap
Run Code Online (Sandbox Code Playgroud)
相反,我想做以下事情:
this._route.params.<any parameter name>
Run Code Online (Sandbox Code Playgroud)