From fd2a6f45fd69ef2f21235404e9ad70ab9f6a7ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?piexlMax=28=E5=A5=87=E6=B7=BC?= Date: Mon, 12 Jan 2026 15:11:59 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A6=96=E9=A1=B5=E7=9A=84=E8=A1=A5=E6=95=91?= =?UTF-8?q?=E6=8E=AA=E6=96=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/permission.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/web/src/permission.js b/web/src/permission.js index d2dd6ba7..23d35a68 100644 --- a/web/src/permission.js +++ b/web/src/permission.js @@ -75,6 +75,22 @@ function addRouteByChildren(route, segments = [], parentName = null) { // 还有子节点,继续向下收集路径片段(忽略外链片段) if (route?.children && route.children.length) { + if(!parentName){ + const firstChild = route.children[0] + if (firstChild) { + const fullParentPath = [...segments, route.path].filter(Boolean).join('/') + const redirectPath = normalizeRelativePath( + [fullParentPath, firstChild.path].filter(Boolean).join('/') + ) + const parentRoute = { + path: normalizeRelativePath(fullParentPath), + name: route.name, // 保留父级名称,以便 defaultRouter 可以指向它 + meta: route.meta, + redirect: "/layout/" + redirectPath, + } + router.addRoute('layout', parentRoute) + } + } const nextSegments = isExternalUrl(route.path) ? segments : [...segments, route.path] route.children.forEach((child) => addRouteByChildren(child, nextSegments, parentName)) return @@ -157,13 +173,6 @@ const handleKeepAlive = async (to) => { } } -// 处理路由重定向 -const handleRedirect = (to, userStore) => { - if (router.hasRoute(userStore.userInfo.authority.defaultRouter)) { - return { ...to, replace: true } - } - return { path: '/layout/404' } -} // 路由守卫 router.beforeEach(async (to, from) => { @@ -176,10 +185,8 @@ router.beforeEach(async (to, from) => { // 处理元数据和缓存 to.meta.matched = [...to.matched] await handleKeepAlive(to) - // 设置页面标题 document.title = getPageTitle(to.meta.title, to) - if (to.meta.client) { return true } @@ -208,15 +215,7 @@ router.beforeEach(async (to, from) => { // 处理异步路由 if (!routerStore.asyncRouterFlag && !WHITE_LIST.includes(from.name)) { const setupSuccess = await setupRouter(userStore) - - if (setupSuccess && userStore.token) { - return handleRedirect(to, userStore) - } - - return { - name: 'Login', - query: { redirect: to.fullPath } - } + return to } return to.matched.length ? true : { path: '/layout/404' }