From 490e56bfbbfdbe50ce10250c926e4ed41c5fe8bd Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 5 Oct 2015 15:32:34 +0100 Subject: [PATCH] Improved url / hash change handling --- src/vector/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 597803f71f..1f6585f721 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -53,14 +53,18 @@ function onHashChange(ev) { } var loaded = false; +var lastLoadedScreen = null; // This will be called whenever the SDK changes screens, // so a web page can update the URL bar appropriately. var onNewScreen = function(screen) { - if (!loaded) return; - var hash = '#/' + screen; - lastLocationHashSet = hash; - window.location.hash = hash; + if (!loaded) { + lastLoadedScreen = screen; + } else { + var hash = '#/' + screen; + lastLocationHashSet = hash; + window.location.hash = hash; + } } // We use this to work out what URL the SDK should @@ -85,5 +89,9 @@ window.addEventListener('hashchange', onHashChange); window.onload = function() { routeUrl(window.location); loaded = true; + if (lastLoadedScreen) { + onNewScreen(lastLoadedScreen); + lastLoadedScreen = null; + } }