location.hash and back history

前端 未结 2 565
臣服心动
臣服心动 2020-12-15 07:42

Is there a function that can be called to prevent the browser from recording a back history entry when changing the hash value?

I am writing a simpl

2条回答
  •  星月不相逢
    2020-12-15 08:13

    You can use replaceState().

    Before you change the hash you save the history, then you change your hash, finally you replace the history with the one you saved.

    Alternatively you can use popState Event.

提交回复
热议问题