如何解决Angular 9-导航开始时获取目标网址
我正在使用 Angular 9 。我需要知道导航开始后便是目标URL。 我想做这样的事情:
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()
是否只有通过使用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
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。