From c8e5bd98cca31d22f75dee164e3376c8e09daaa5 Mon Sep 17 00:00:00 2001 From: Lukas Bestle Date: Tue, 16 Aug 2016 11:19:55 +0200 Subject: [PATCH] Fix AJAX popstate event --- shared/3-sugar/ajax/ajax.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shared/3-sugar/ajax/ajax.js b/shared/3-sugar/ajax/ajax.js index 85d87ff..12a7623 100644 --- a/shared/3-sugar/ajax/ajax.js +++ b/shared/3-sugar/ajax/ajax.js @@ -56,10 +56,10 @@ // Just scroll to the top/element if the link points to the current page // In this case, we also don't want to reload, so we return true - if(target.pathname === window.location.pathname) { + if(mode === 'normal' && target.pathname === window.location.pathname) { var element; if(target.hash) { - if(mode === 'normal' && target.hash !== '#top') { + if(target.hash !== '#top') { history.pushState({}, document.title, target.href); } element = document.getElementById(target.hash.substr(1)); @@ -162,6 +162,9 @@ if(app.go(link)) e.preventDefault(); }); + // Replace the state for the normal page load + history.replaceState({}, document.title, window.location.href); + // Listen on the popstate event on window window.addEventListener('popstate', function(e) { if(e.state !== null) app.go(window.location.href, 'popstate');