Skip to content

Commit 490e56b

Browse files
committed
Improved url / hash change handling
1 parent 61f951a commit 490e56b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/vector/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ function onHashChange(ev) {
5353
}
5454

5555
var loaded = false;
56+
var lastLoadedScreen = null;
5657

5758
// This will be called whenever the SDK changes screens,
5859
// so a web page can update the URL bar appropriately.
5960
var onNewScreen = function(screen) {
60-
if (!loaded) return;
61-
var hash = '#/' + screen;
62-
lastLocationHashSet = hash;
63-
window.location.hash = hash;
61+
if (!loaded) {
62+
lastLoadedScreen = screen;
63+
} else {
64+
var hash = '#/' + screen;
65+
lastLocationHashSet = hash;
66+
window.location.hash = hash;
67+
}
6468
}
6569

6670
// We use this to work out what URL the SDK should
@@ -85,5 +89,9 @@ window.addEventListener('hashchange', onHashChange);
8589
window.onload = function() {
8690
routeUrl(window.location);
8791
loaded = true;
92+
if (lastLoadedScreen) {
93+
onNewScreen(lastLoadedScreen);
94+
lastLoadedScreen = null;
95+
}
8896
}
8997

0 commit comments

Comments
 (0)