]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/router.js
Ignore hashchange-triggered popstate events here too
[rails.git] / app / assets / javascripts / router.js
index 654ec860b549b2483d2a8fea51a46edc9bc5eec7..7a61af106df9696b36ebc4bb68a8cda13be12da7 100644 (file)
@@ -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');