【发布时间】:2020-08-18 15:14:12
【问题描述】:
我需要 Angular TS 文件的 OnInit 函数中的 Previous URL。
ngOnInit() {
this.router.events
.pipe(filter((e: any) => e instanceof RoutesRecognized),
pairwise()
).subscribe((e: any) => {
console.log(e[0].urlAfterRedirects); // previous url
});
}
我可以通过上面的代码,但这会重复多次,因为我在 Parent 下有很多子组件。 我需要任何其他方法,它只运行一次
【问题讨论】:
-
保存在 sessionStorage 或 localStorage 中
-
@ShlokNangia 重复多次
-
@ShlokNangia 如果我访问了任何其他组件,此代码也会重复!!!!