handle deep links

This commit is contained in:
Rich Harris
2017-12-24 07:53:39 -05:00
committed by GitHub
parent 9a936669c6
commit c8366dec74
3 changed files with 45 additions and 4 deletions

View File

@@ -177,10 +177,17 @@ export function init(_target, _routes) {
inited = true;
}
scroll_history[uid] = scroll_state();
setTimeout(() => {
const { hash, href } = window.location;
history.replaceState({ id: uid }, '', window.location.href);
navigate(new URL(window.location), uid);
const deep_linked = hash && document.querySelector(hash);
scroll_history[uid] = deep_linked ?
{ x: 0, y: deep_linked.getBoundingClientRect().top } :
scroll_state();
history.replaceState({ id: uid }, '', href);
navigate(new URL(window.location), uid);
});
}
function which(event) {