Pas*_*cal 6 typescript angular2-routing angular
如何获取订阅的router.events内部的活动路由数据(如params)?
我也没有想订阅this.route.params!
// Catch any events in a certain component, where I subscribe to it!
this.router.events.subscribe(event =>
{
// The event object has only the url (when is NavigationStart/End), there is nothing useful for me
});
Run Code Online (Sandbox Code Playgroud)
更新
我的问题有所不同,因为我不问如何对路由器事件做出反应!
我要求如何在router.events中获取激活的路由参数!
那肯定是有区别的!
this.router.events.subscribe(event =>
{
console.log(this.router.routerState.root);
console.log(this.router.routerState.root.firstChild);
console.log(this.router.routerState.root.firstChild && this.router.routerState.root.firstChild.firstChild);
});
Run Code Online (Sandbox Code Playgroud)
merge(of(this.route.snapshot.params), this.router.events.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => this.route),
map((route) => {
while (route.firstChild) route = route.firstChild;
return route;
}),
filter((route) => route.outlet === 'primary'),
mergeMap(route => route.params),
)).subscribe(p => {})
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3645 次 |
最近记录: |