From e68e3e9150c1e02063664afcf8f6028903c59cb4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 8 Nov 2013 12:19:47 -0800 Subject: [PATCH] Ignore hashchange-triggered popstate events here too --- app/assets/javascripts/router.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/router.js b/app/assets/javascripts/router.js index 654ec860b..7a61af106 100644 --- a/app/assets/javascripts/router.js +++ b/app/assets/javascripts/router.js @@ -50,7 +50,12 @@ OSM.Router = function(rts) { currentRoute.run('load', currentPath); if (window.history && window.history.pushState) { - $(window).on('popstate', function() { + // Set a non-null initial state, so that the e.originalEvent.state + // check below works correctly when going back to the initial page. + window.history.replaceState({}, document.title, window.location); + + $(window).on('popstate', function(e) { + if (!e.originalEvent.state) return; // Is it a real popstate event or just a hash change? var path = window.location.pathname + window.location.search; if (path === currentPath) return; currentRoute.run('unload'); -- 2.43.2