cancel navigation if overtaken by a second navigation - fixes #48

This commit is contained in:
Rich Harris
2017-12-24 20:37:00 -05:00
parent 75aedf4663
commit 3c4ebcda30
4 changed files with 54 additions and 7 deletions

View File

@@ -35,10 +35,14 @@ function select_route(url) {
}
}
function render(Component, data, scroll) {
let current_token;
function render(Component, data, scroll, token) {
Promise.resolve(
Component.preload ? Component.preload(data) : {}
).then(preloaded => {
if (current_token !== token) return;
if (component) {
component.destroy();
} else {
@@ -83,7 +87,7 @@ function navigate(url, id) {
}
selected.route.load().then(mod => {
render(mod.default, selected.data, scroll_history[id]);
render(mod.default, selected.data, scroll_history[id], current_token = {});
});
cid = id;