可以取消更改窗口历史记录 [英] CanDeactivate changing the window history
本文介绍了可以取消更改窗口历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当它返回false时,我都会遇到canDeactivate()的问题,它会更改窗口历史记录,就像它变为true时一样,如果我按下后退"按钮.我正在导航到其他URL或不在应用程序本身之外.
I am facing some issue with canDeactivate() whenever it returns false it is changing the window history as when it became true and if i hit the back button. I am navigating to some other URL or out of the app itself.
请帮助我
推荐答案
此处是问题,但仍然没有解决.
Here is the issue, but it still isn't fixed.
作为一种解决方法,您可以手动将活动网址放回历史记录:
As a workaround, you can manually put the active url back to the history:
export class CanDeactivateGuard implements CanDeactivate<any> {
constructor(
private readonly location: Location,
private readonly router: Router
) {}
canDeactivate(component: any, currentRoute: ActivatedRouteSnapshot): boolean {
if (myCondition) {
const currentUrlTree = this.router.createUrlTree([], currentRoute);
const currentUrl = currentUrlTree.toString();
this.location.go(currentUrl);
return false;
} else {
return true;
}
}
}
这篇关于可以取消更改窗口历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文