mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-11 17:15:44 +08:00
feat: 缓存上次访问的路由菜单 (#6897)
Refs https://github.com/1Panel-dev/1Panel/issues/6868
This commit is contained in:
parent
f79adc9bc0
commit
c52dddfa67
1 changed files with 24 additions and 1 deletions
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue