From 24ffef5d69e5c090b116dfe7b2366d3bb1bb5f44 Mon Sep 17 00:00:00 2001 From: Suven-p Date: Sat, 16 Nov 2024 06:49:42 +0545 Subject: [PATCH] Bugfix: Broke functionality in previous commit --- src/router.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/router.js b/src/router.js index 9a2db859d..9e6fcdd9c 100644 --- a/src/router.js +++ b/src/router.js @@ -199,19 +199,22 @@ const router = createRouter({ }); router.beforeEach((to, from) => { - // If the path is same, either the query or has has changed so avoid changing query params - // Without this check, modifying any query params will be blocked // Check if redirectedFrom is defined to check if this function has already been run // Without this check, the router will be stuck in an infinite loop - if (to.fullPath !== from.fullPath && !to.redirectedFrom) { - return { - ...to, - query: { - ...to.query, - ...from.query, - }, - }; + if (to.redirectedFrom) return; + + // If the user is navigating to same page but to.query is empty, they have clicked on the same link + // For example: Clicked on Add monitor twice + if (to.path === from.path && Object.keys(to.query).length !== 0) { + return; } + return { + ...to, + query: { + ...to.query, + ...from.query, + }, + }; }); export { router };