Slide 28
Slide 28 text
$(document).on('click', 'a[href^="/"]', function(e) {
var target = e.currentTarget;
if (!e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
e.preventDefault();
url = target.pathname;
navigate(url, { triggered: true });
}
});
function navigate(url, data) {
history.pushState(data, '', url);
}
window.onpopstate = function (event) {
if (event.state.triggered) {
ajaxLoad(location.pathname);
}
}
Now when the user navigates to a url, or we
manually push a new url (pushState), it fires
popstate, and we ajaxLoad new content.