What are the differences between history.pushState & location.hash?

前端 未结 8 1401
既然无缘
既然无缘 2020-11-30 03:29

I\'m trying to update the URL using window.location.hash or history.pushState.

What are the differences and advantages of each method?

8条回答
  •  难免孤独
    2020-11-30 03:51

    I personally prefer pushState because it makes nicer looking URLs and I think that is important for user experience.

    You can use history.pushState with a hash fallback using the history.js polyfill if you want to use pushState, but don't want to have issues with older browser support.

提交回复
热议问题