From d63c35192d621ac4f78aee80561e6ab715c539a0 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 26 Mar 2025 15:01:23 +0100 Subject: [PATCH] fix: refs #8534 update stateQueryGuard to check route changes and improve loading state handling --- src/router/hooks.js | 9 ++++++--- src/router/index.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/router/hooks.js b/src/router/hooks.js index e5d5288a906..add773e7fcf 100644 --- a/src/router/hooks.js +++ b/src/router/hooks.js @@ -38,9 +38,11 @@ export async function navigationGuard(to, from, next, Router, state) { next(); } -export async function stateQueryGuard(next) { - const stateQuery = useStateQueryStore(); - await waitUntilFalse(stateQuery.isLoading()); +export async function stateQueryGuard(to, from, next) { + if (to.name !== from.name) { + const stateQuery = useStateQueryStore(); + await waitUntilFalse(stateQuery.isLoading()); + } next(); } @@ -82,6 +84,7 @@ function waitUntilFalse(ref) { const stop = watch( ref, (val) => { + console.log('val: ', val); if (!val) { stop(); resolve(); diff --git a/src/router/index.js b/src/router/index.js index b90f33e74dc..f8659308ae6 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -23,7 +23,7 @@ export { Router }; export default defineRouter(() => { const state = useState(); Router.beforeEach((to, from, next) => navigationGuard(to, from, next, Router, state)); - Router.beforeEach((to, from, next) => stateQueryGuard(next)); + Router.beforeEach((to, from, next) => stateQueryGuard(to, from, next)); Router.afterEach((to) => setPageTitle(to)); Router.onError(({ message }) => {