dc_*_*a98 1 url-routing angular-routing angular angular-router angular9
我正在使用Angular 9。我需要在导航开始后立即知道哪个将是目标网址。我想做这样的事情:
constructor(router: Router) {
this.router = router;
}
this.router.events.pipe(
filter(event => event instanceOf NavigationStart),
map(event => {
//get somehow the destination url of this navigation just started
})
).subscribe()
Run Code Online (Sandbox Code Playgroud)
有没有办法只使用 Angular Router来实现这一点?
您可以使用
this.router.events.pipe(
filter((e: Event): e is NavigationStart => e instanceof NavigationStart)
).subscribe((e: NavigationStart) => {
e.url // contains the url you will go to
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1262 次 |
最近记录: |