From df83a7be19a379fa913235f3ca8f57678623cf1b Mon Sep 17 00:00:00 2001 From: Morteza Karimi Date: Fri, 24 May 2024 15:11:06 -0700 Subject: [PATCH] Add router hook to preserve query strings --- quasar_site/src/layouts/MainLayout.vue | 1 - quasar_site/src/router/index.js | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/quasar_site/src/layouts/MainLayout.vue b/quasar_site/src/layouts/MainLayout.vue index ca171272..6ad78612 100644 --- a/quasar_site/src/layouts/MainLayout.vue +++ b/quasar_site/src/layouts/MainLayout.vue @@ -214,7 +214,6 @@ export default { const newPath = `${this.baseUrl}${newState}`.toLowerCase(); if (this.$route.path.toLowerCase() !== newPath) { - console.log("pushing path") this.$router.push(newPath); } ViewModel.setSelectedItem(newState); diff --git a/quasar_site/src/router/index.js b/quasar_site/src/router/index.js index ca3cd61c..95048d49 100644 --- a/quasar_site/src/router/index.js +++ b/quasar_site/src/router/index.js @@ -26,5 +26,17 @@ export default route(function (/* { store, ssrContext } */) { history: createHistory(process.env.VUE_ROUTER_BASE) }) + function hasQueryParams(route) { + return !!Object.keys(route.query).length; + } + + Router.beforeEach((to, from, next) => { + if (!hasQueryParams(to) && hasQueryParams(from)) { + next({ path: to.path, query: from.query, hash: to.hash }); + } else { + next(); + } + }); + return Router })