Angular 7路由器 - 导航而不添加历史记录

问题描述 投票:0回答:1

我现在需要你的帮助!

我有Angular Router,我想导航到另一个url而不将其添加到浏览器历史记录中,因为后退按钮会一次又一次地将用户返回到url。

this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);

我的代码在这里。我只能使用Angular乐器或者我需要使用History API吗?谢谢!

javascript angular router history
1个回答
0
投票

正如@IngoBürk在评论中提到的,您可以在不使用skiplocationChange的情况下获得相同的结果

 this.router.replaceUrl('path')

skipLocationChange

在不将新状态推入历史的情况下进行导航。

this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });

参考:https://angular.io/api/router/NavigationExtras#skipLocationChange

© www.soinside.com 2019 - 2024. All rights reserved.