Back button fails after window.location.replace(href);

亡梦爱人 提交于 2019-12-04 02:47:08

Instead of using replace, use the following:

window.location.href = ''

Adding to MarcoK's answer.

When using replace you are replacing the history state so you are not pushing one more state to the history.

If you have the following:

Page1 to State1

Page2 to State2

and then you use replace you will be replacing Page3 to State2.

When you press the back button you will go from State2 to State1 and that is why you are going to Page1.

When using window.location.href you are adding one more state so Page3 will be set to State3 and when you click the back button you will go to State2 wich has Page2 as URL.

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