diff --git a/common/App.svelte b/common/App.svelte index 48a4522..61b6fc1 100644 --- a/common/App.svelte +++ b/common/App.svelte @@ -14,7 +14,34 @@ page.set('schedule') }) + let ignoreNext = false + function addPage (value, type) { + if (ignoreNext) { + ignoreNext = false + return + } + history.pushState({ type, value }, '', './?id=' + Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString()) + } + page.subscribe((value) => { + addPage(value, 'page') + }) + view.subscribe((value) => { + addPage(value, 'view') + }) + addPage('home', 'page') + + window.addEventListener('popstate', e => { + const { state } = e + if (!state) return + ignoreNext = true + view.set(null) + if (state.type === 'page') { + page.set(state.value) + } else { + view.set(state.value) + } + })