Angular Router Events: NavigationEnd — How to filter only the last event

*爱你&永不变心* 提交于 2019-12-06 08:26:11

PS. There's a better way to filter using a 'typeguard', you then get the proper type without having to assert it again:

firstChildData$ = this.router.events.pipe(

            filter((e): e is NavigationEnd => e instanceof NavigationEnd), 

            map(e => { // e is now NavigationEnd }

This is actually necessary in strict mode.

Okay, after reading through the posted articles above and rethinking what I really want to achieve I found out that my approach was definitely too complicated. Because actually I only need access to the currently called route. And so I started from scratch and came across this small but very effective solution:

this.router.events.subscribe(value => {
    console.log('current route: ', router.url.toString());
});

Thanks to all who shared a comment in oder to support me! It helped al lot as I was able to tie up loose ends.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!