How to skip a page in browser history when navigating back?

允我心安 提交于 2019-12-07 04:14:03

问题


I have an Angular 2 app with the Router. Let's say the user is on a page A in the app, he then navigates to a page B and then to a page C. At this moment when he clicks the Back button on the browser I want him to get back to the page A (by skipping B). How can I achieve it?


回答1:


When navigating from B to C one has to set { replaceUrl: true }:

this.router.navigate(["/c"], { replaceUrl: true });

This replaces the page B by C in the browser history.




回答2:


Quick and easy solution is

Use navigation in your typescript instead of html file .

And specify the parameter

{ skipLocationChange: true }

Proper solution is to write your own navigation strategy and specify in app.modules.ts



来源:https://stackoverflow.com/questions/41874826/how-to-skip-a-page-in-browser-history-when-navigating-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!