2017-02-23 167 views
1

我使用下面的代碼更改頁面的URL無需重新加載整個頁面:爲什麼history.pushState不工作?

alert(window.location.href); 
window.history.pushState({} , 'foo', '/foo'); 
alert(window.location.href); 

結果:

第一個警報

file:///C:/Users/name/Desktop/html/first.html 

第二個提醒
沒有警報和URL沒有變化,但我期待以下內容:

file:///C:/Users/name/Desktop/html/foo 

毛刺在哪裏?以及如何更改瀏覽器URL而不重新加載頁面?

+4

的[history.pushState將不起作用]可能的複製(http://stackoverflow.com/questions/39814218/history-pushstate-will-not工作) – JJJ

回答