Skip to content

Commit

Permalink
Detect back/forward
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchuan committed Aug 21, 2023
1 parent e25b6fe commit 5f2605b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
});
}
onMount(() => {
function init() {
let query = new URLSearchParams(location.search);
let name = query.get('name');
codeFromQuery = query.get('code');
Expand All @@ -157,7 +157,15 @@
} else {
handleSelect(name);
}
}
onMount(() => {
init();
window.addEventListener('popstate', init);
mounted = true;
return () => {
window.removeEventListener(init);
}
});
</script>

Expand Down

0 comments on commit 5f2605b

Please sign in to comment.