Can you use hash navigation without affecting history?

后端 未结 4 589
旧巷少年郎
旧巷少年郎 2020-12-07 10:12

I\'m afraid it might be impossible but is there a way to change the hash value of a URL without leaving an entry in the browser\'s history and witho

4条回答
  •  借酒劲吻你
    2020-12-07 10:51

    location.replace("#hash_value_here"); worked fine for me until I found that it doesn't work on IOS Chrome. In which case, use:

    history.replaceState(undefined, undefined, "#hash_value")
    

    history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.

    Remember to keep the # or the last part of the url will be altered.

提交回复
热议问题