Ale*_*ork 15 javascript history router angular
使用 Angular Router,我想导航到另一个 url 而不将其添加到浏览器历史记录中。
this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);
Run Code Online (Sandbox Code Playgroud)
我可以只用 Angular 来做吗?
Elr*_*ron 24
感谢NavigationExtras,您现在可以replaceUrl: boolean在内部使用navigate()
这将替换当前的 url,新的 URL 将在地址栏中更新:
this.router.navigate([`/somewhere`], { replaceUrl: true });
Run Code Online (Sandbox Code Playgroud)
这样,当您按回时,它就不会记住历史记录中的上一页。
正如@IngoBürk 在评论中提到的,您可以在不使用 skiplocationChange 的情况下获得相同的结果
this.router.replaceUrl('path')
Run Code Online (Sandbox Code Playgroud)
跳过位置更改
在不将新状态推入历史的情况下进行导航。
this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });
Run Code Online (Sandbox Code Playgroud)
参考:https : //angular.io/api/router/NavigationExtras#skipLocationChange
| 归档时间: |
|
| 查看次数: |
15119 次 |
| 最近记录: |