你好,我已经用这样的 id 声明了我的路线 {path: 'spreadsheet/:id', component: ContactParent}
所以在这里我可以获得 id
通过使用 ActivatedRoute
但我如何获得 spreadsheet
,如果我这样做 this.router.url
它会给我 spreadsheet/20
但我只需要 spreadsheet
最佳答案
试试这个...
constructor( private route: ActivatedRoute ) {
console.log(route.pathFromRoot[1].snapshot.url[0].path);
}
例如,如果您转到 http://localhost:4200/spreadsheet/3 ,上面的代码将记录“电子表格”
关于angular - 从 Angular 2路由获取激活路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46440324/