Javascript Angular 7路由器-导航而不添加历史记录
使用Angular Router,我希望导航到另一个url,而不将其添加到浏览器历史记录中Javascript Angular 7路由器-导航而不添加历史记录,javascript,angular,router,history,Javascript,Angular,Router,History,使用Angular Router,我希望导航到另一个url,而不将其添加到浏览器历史记录中 this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`); 我可以只使用角度吗?正如评论中提到的@IngoBürk,您可以在不使用skiplocationChange的情况下获得相同的结果 this.router.replaceUrl('path') skipLocationChange 导航时不会将新状态推入历史 Ref:
this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);
我可以只使用角度吗?正如评论中提到的@IngoBürk,您可以在不使用skiplocationChange的情况下获得相同的结果
this.router.replaceUrl('path')
skipLocationChange
导航时不会将新状态推入历史
Ref:感谢您现在可以在导航()中使用replaceUrl:boolean
这将替换当前url,新url将在地址栏中更新:
this.router.navigate([`/somewhere`], { replaceUrl: true });
这样,当您按back键时,它将不记得历史记录中的上一页。我认为这里的replaceUrl是正确答案。skipLocationChange也不会更新URL,而且这听起来不像OP想要的。我看不出你的编辑与我的评论有什么关系?我的意思是使用replaceUrl
而不是skipLocationChange
。它也是NavigationExtras
的一个选项。不,它替换状态。这意味着URL将在地址栏中更新,但堆栈上没有新事件,因此单击“上一步”按钮将返回与没有导航相同的上一页。如果您使用skipLocationChange,也会产生这种效果,但地址栏中的URL不会更新。您的新编辑仍然是错误的。同样,您需要使用replaceUrl。现在,您只需编辑为完全不使用任何标志,这是一个正常的导航。我现在不想再解释了,我想已经很清楚了。。。
this.router.navigate([`/somewhere`], { replaceUrl: true });