From c52dddfa67267c80fcd6811282849135af6ff031 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:18:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E7=9A=84=E8=B7=AF=E7=94=B1=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=20(#6897)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/6868 --- frontend/src/routers/index.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/src/routers/index.ts b/frontend/src/routers/index.ts index 6959fec84..cd40cb6a0 100644 --- a/frontend/src/routers/index.ts +++ b/frontend/src/routers/index.ts @@ -5,6 +5,8 @@ import { AxiosCanceler } from '@/api/helper/axios-cancel'; const axiosCanceler = new AxiosCanceler(); +let isRedirecting = false; + router.beforeEach((to, from, next) => { NProgress.start(); axiosCanceler.removeAllPending(); @@ -31,11 +33,32 @@ router.beforeEach((to, from, next) => { return; } + const activeMenuKey = 'cachedRoute' + (to.meta.activeMenu || ''); + const cachedRoute = localStorage.getItem(activeMenuKey); + + if ( + to.meta.activeMenu && + to.meta.activeMenu != from.meta.activeMenu && + cachedRoute && + cachedRoute !== to.path && + !isRedirecting + ) { + isRedirecting = true; + next(cachedRoute); + NProgress.done(); + return; + } + if (!to.matched.some((record) => record.meta.requiresAuth)) return next(); + return next(); }); -router.afterEach(() => { +router.afterEach((to) => { + if (to.meta.activeMenu && !isRedirecting) { + localStorage.setItem('cachedRoute' + to.meta.activeMenu, to.path); + } + isRedirecting = false; NProgress.done(); });