Javascript 在这种情况下,如何转到html5历史推送的上一个url?

Javascript 在这种情况下,如何转到html5历史推送的上一个url?,javascript,jquery,html,url,html5-history,Javascript,Jquery,Html,Url,Html5 History,我正在使用html5历史api,我这样做是为了更改url: history.replaceState({url: "/hello/stack/", null, "/hello/stack/"); history.replaceState({url: "/overflow/", null, "/overflow/"); 那么最终的结果是: http://myweb.com/hello/overflow/ 然后,如果我按下浏览器的上一个按钮,它会将我重定向到http://myweb.com/,而

我正在使用html5历史api,我这样做是为了更改url:

history.replaceState({url: "/hello/stack/", null, "/hello/stack/");
history.replaceState({url: "/overflow/", null, "/overflow/");
那么最终的结果是:

http://myweb.com/hello/overflow/
然后,如果我按下浏览器的上一个按钮,它会将我重定向到
http://myweb.com/
,而不是之前推送的历史url:
http://myweb.com/hello/

有一种方法可以在按下浏览器的“后退”按钮或类似的方法时调用
history.go(-1)

任何帮助、提示或建议都将不胜感激,如果您需要更多信息,请告诉我,我将编辑此帖子。

replaceState
替换当前状态,换句话说,它不会添加新状态。如果要向历史记录中添加更多项目,请改用
pushState

replaceState
替换当前状态,换句话说,它不会添加新状态。如果您希望向历史记录中添加更多项目,请改用
pushState

我想您需要
history.pushState
而不是
history.replaceState
。我想您需要
history.pushState
而不是
history.replaceState