Angular2 router causes extra browser history entry

蹲街弑〆低调 提交于 2019-12-12 03:34:47

问题


In Angular2 I want to be able to navigate directly to a route and be able to hit back (in the browser) once to go to the last page that I was on.

If you first go to any website (I used google.com), then put this plnkr in your browser bar: http://run.plnkr.co/9D5IDnHv0UkUFM82/. If you hit the browser's back button, instead of taking you to the previous page, it keeps you on the plnkr until you hit back again.

I believe this is because although I navigated directly to the "home" route, when I hit http://run.plnkr.co/9D5IDnHv0UkUFM82/ (note that i set my base url to /9D5IDnHv0UkUFM82/) it routes me to the home url even though I am already there.

This problem also occurs in the Angular2 Tutorial app here: https://angular.io/resources/live-examples/toh-5/ts/plnkr.html

Notice when the route loads, there is an extra entry in your browser's history. You can hit "back" on your browser and it will stay on the plnkr until you hit "back" again. This is not an artifact caused by plnkr. This occurs on my local angular2 setup as well.


回答1:


This is a known issue

See also
- https://github.com/angular/angular/issues/5025

There is already a pull request
- https://github.com/angular/angular/pull/6069



来源:https://stackoverflow.com/questions/36025032/angular2-router-causes-extra-browser-history-entry

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