我访问我的应用程序的一个页面:
myApp.com/#/accident/(carsContainer:robustness)
在事故部分,我想提取“健壮性”部分。我想我必须使用ActivatedRoute,但找不到一种方法
发布于 2017-09-21 16:31:21
在accident组件中,您可以订阅路由器事件并获取url,然后从其中提取您需要的任何内容。就像这样:
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
constructor(private activatedRoute: ActivatedRoute, private router: Router){}
ngOnInit() {
this.router.events
.filter((event) => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map((route) => {
while (route.firstChild) route = route.firstChild;
console.log(route.snapshot.url[0].path)
return route;
})
.subscribe((event) => {
console.log('NavigationEnd:', event);
});
}https://stackoverflow.com/questions/46348093
复制相似问题