Skip to content

Commit

Permalink
Allow using browser history to go back to previous PPNs
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Aug 8, 2024
1 parent 7f0f4d2 commit 98449f4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ const initPromise = (async () => {
console.timeEnd("Init")
})()
onMounted(() => {
const initializeFromUrl = () => {
// Get PPN parameter from URL
const urlParams = new URLSearchParams(window.location.search)
state.ppn = urlParams.get("ppn") || null
})
}
onMounted(initializeFromUrl)
addEventListener("popstate", initializeFromUrl)
function updateUrl({ ppn } = {}) {
const hash = window.location.hash
Expand All @@ -78,7 +80,7 @@ function updateUrl({ ppn } = {}) {
}
// Note that hash/fragment needs to be at the end of the URL, otherwise the search params will be considered part of the hash!
url += hash
window.history.replaceState({}, "", url)
window.history.pushState({}, "", url)
}
watch(() => state.ppn, async (ppn) => {
Expand Down

0 comments on commit 98449f4

Please sign in to comment.