我在这里使用History.js https://github.com/browserstate/history.js/
这就是我目前所拥有的:
var History = window.History;
if (History.enabled) {
// set initial state for first page that is loaded
var State = History.getState();
History.pushState({urlPath: window.location.pathname}, $("title").text(), State.urlPath);
}
else {
return false;
}
// content update and back/forward button handler
History.Adapter.bind(window, 'statechange', function(){
var s = History.getState();
History.log(s.data, s.title, s.url);
// update view based on load type
OnLoadPageByURL(s.data.urlPath);
});
// navigation link handler(s)
$('body').on('click', 'a', function(e){
e.preventDefault();
var load = $(e.currentTarget).data('load');
var urlPath = $(this).attr('href');
var title = $(this).text();
History.pushState({ load: load, urlPath: urlPath }, title, urlPath);
});
一切似乎都有效,但后退按钮似乎无法正常工作?我做错了什么?