小编Kal*_*ala的帖子

获取组件中的路由参数

我正在研究 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)

typescript angular-routing angular angular-router

8
推荐指数
1
解决办法
1万
查看次数