From a9c06a6aaf770ab1c547cb4b0cbf246d55fee27a Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Sun, 6 Mar 2022 23:56:39 +0100 Subject: [PATCH] Try improve history navigation by pushing popup changes --- src/modules/popup.js | 7 ++++++- src/routes.js | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/popup.js b/src/modules/popup.js index 0df4079..332361a 100644 --- a/src/modules/popup.js +++ b/src/modules/popup.js @@ -23,7 +23,12 @@ const updateQueryParams = (id = null, type = null) => { window.location.port ? `:${window.location.port}` : "" }${window.location.pathname}${params.toString().length ? `?${params}` : ""}`; - window.history.replaceState({}, "search", url); + if (!window.preventPushState) { + window.history.pushState({}, "search", url); + window.preventPushState = false; + } else { + window.history.replaceState({}, "search", url); + } }; export default { diff --git a/src/routes.js b/src/routes.js index 6a8fcee..c5df6ea 100644 --- a/src/routes.js +++ b/src/routes.js @@ -87,9 +87,13 @@ const loggedIn = () => store.getters["user/loggedIn"]; const popupIsOpen = () => store.getters["popup/isOpen"]; const hamburgerIsOpen = () => store.getters["hamburger/isOpen"]; +window.preventPushState = false; +window.onpopstate = () => (window.preventPushState = true); + router.beforeEach((to, from, next) => { store.dispatch("documentTitle/updateTitle", to.name); const { movie, show, person } = to.query; + if (movie) store.dispatch("popup/open", { id: movie, type: "movie" }); else if (show) store.dispatch("popup/open", { id: show, type: "show" }); else if (person) store.dispatch("popup/open", { id: person, type: "person" });