Try improve history navigation by pushing popup changes

This commit is contained in:
2022-03-06 23:56:39 +01:00
parent 9bb5211b4e
commit a9c06a6aaf
2 changed files with 10 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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" });