From 5ef45d93d3f030989a44ee64d772bed9e61cc03c Mon Sep 17 00:00:00 2001 From: OFF0 Date: Wed, 2 Aug 2023 12:27:22 +0200 Subject: [PATCH] nav: add history entry only once onload reloading the page always added a history entry breaking back button functionality. fixed by only adding a history entry on load if the history is empty, so that reloads will not add the same entry over and over again. --- src/main.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 2b8b24f..b4d0b23 100644 --- a/src/main.ts +++ b/src/main.ts @@ -216,7 +216,11 @@ const route = (path: string) => { // onload route(location.pathname); -history.pushState({}, '', location.pathname); + +// only push a new entry if there is no history onload +if (!history.length) { + history.pushState({}, '', location.pathname); +} window.addEventListener('popstate', (event) => { route(location.pathname);