pushState与replaceState区别

history.pushState(state, title, url)


将当前URL和history.state加入到history中,并用新的state和URL替换当前。不会造成页面刷新。

state:与要跳转到的URL对应的状态信息。

title:可以不传

url:要跳转到的URL地址,不能跨域。

history.replaceState(state, title, url)


用新的state和URL替换当前。不会造成页面刷新。

state:与要跳转到的URL对应的状态信息。

title:可以不传

url:要跳转到的URL地址,不能跨域。


两者看似没有区别,其实区别很大的,pushState是添加历史记录的,而replaceState是不添加的。

原文地址:https://www.cnblogs.com/guxuelong/p/5076701.html