菜单修复
This commit is contained in:
parent
f7b5247e0c
commit
e21b444cdb
@ -385,7 +385,8 @@
|
||||
// 关闭全部
|
||||
const closeAll = () => {
|
||||
tabsViewStore.closeAllTabs();
|
||||
router.replace(PageEnum.BASE_HOME_REDIRECT);
|
||||
router.replace(storage.get('FIRST-PATH'));
|
||||
// router.replace(PageEnum.BASE_HOME_REDIRECT);
|
||||
updateNavScroll();
|
||||
};
|
||||
|
||||
|
@ -164,3 +164,10 @@ export const dynamicImport = (
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 查找第一个路由
|
||||
* */
|
||||
export const findFirstRoutePath = (routes)=>{
|
||||
return routes[0].redirect?routes[0].redirect:routes[0].path
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import { ACCESS_TOKEN } from '@/store/mutation-types';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { ErrorPageRoute,AboutPageRoute } from '@/router/base';
|
||||
import { findFirstRoutePath } from '@/router/generator-routers';
|
||||
import {findTreeByPath} from "@/utils/auth";
|
||||
import NProgress from 'nprogress';
|
||||
|
||||
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
||||
@ -17,10 +19,6 @@ export function createRouterGuards(router: Router) {
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
NProgress.start();
|
||||
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
|
||||
next(PageEnum.BASE_HOME);
|
||||
return;
|
||||
}
|
||||
|
||||
// Whitelist can be directly entered
|
||||
if (whitePathList.includes(to.path as PageEnum)) {
|
||||
@ -64,15 +62,20 @@ export function createRouterGuards(router: Router) {
|
||||
routes.forEach((item) => {
|
||||
router.addRoute(item as unknown as RouteRecordRaw);
|
||||
});
|
||||
|
||||
//添加404
|
||||
const isErrorPage = router.getRoutes().findIndex((item) => item.name === ErrorPageRoute.name);
|
||||
if (isErrorPage === -1) {
|
||||
router.addRoute(ErrorPageRoute as unknown as RouteRecordRaw);
|
||||
}
|
||||
router.addRoute(AboutPageRoute as unknown as RouteRecordRaw);
|
||||
|
||||
const redirectPath = (from.query.redirect || to.path) as string;
|
||||
const firstRoutePath = findFirstRoutePath(routes)
|
||||
storage.set('FIRST-PATH',firstRoutePath)
|
||||
if (from.path === LOGIN_PATH && (to.name === 'errorPage' || !to.name)) {
|
||||
next(firstRoutePath);
|
||||
return;
|
||||
}
|
||||
let formPath = findTreeByPath(routes,from.query.redirect).length > 0 ? from.query.redirect:to.path
|
||||
const redirectPath = (formPath) as string;
|
||||
const redirect = decodeURIComponent(redirectPath);
|
||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
||||
asyncRouteStore.setDynamicAddedRoute(true);
|
||||
|
@ -175,6 +175,20 @@ export const buildTree =(array)=> {
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
/***
|
||||
* 递归查找
|
||||
*/
|
||||
export const findTreeByPath =(tree, path, result = []) =>{
|
||||
for (const node of tree) {
|
||||
if (node.path === path) {
|
||||
result.push(node);
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
findTreeByPath(node.children, path, result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export const getComponentName = (route: RouteLocationNormalized) => {
|
||||
|
Loading…
Reference in New Issue
Block a user