Back button fails after [removed].replace(href);

前端 未结 2 1123
眼角桃花
眼角桃花 2021-02-12 20:38

I made simple function which makes all container behave like link ("a" element).

function allHot(element){
$(element)
.click(
    function(){
    var hr         


        
2条回答
  •  悲哀的现实
    2021-02-12 21:02

    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.

提交回复
热议问题