mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-23 14:54:05 +00:00
Preserve query params on route change
This commit is contained in:
parent
c6a9a78175
commit
b68cdf70d6
1 changed files with 17 additions and 1 deletions
|
@ -192,8 +192,24 @@ const routes = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const router = createRouter({
|
const router = createRouter({
|
||||||
linkActiveClass: "active",
|
linkActiveClass: "active",
|
||||||
history: createWebHistory(),
|
history: createWebHistory(),
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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.path !== from.path && !to.redirectedFrom) {
|
||||||
|
return {
|
||||||
|
path: to.path,
|
||||||
|
query: { ...to.query, ...from.query },
|
||||||
|
params: to.params,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export { router };
|
||||||
|
|
Loading…
Reference in a new issue