diff --git a/resources/admin/router/guard/index.ts b/resources/admin/router/guard/index.ts index d4dc54f..ed28b7c 100644 --- a/resources/admin/router/guard/index.ts +++ b/resources/admin/router/guard/index.ts @@ -41,10 +41,14 @@ const guard = (router: Router) => { asyncRoutes.forEach((route: Menu) => { router.addRoute(route as unknown as RouteRecordRaw) }) + // 在动态路由之后挂载匹配 404 路由 + router.addRoute({ + path: '/:pathMatch(.*)*', + redirect: '/404', + }) } - next({ ...to, replace: true }) + next({ ...to, replace: true }); } catch (e) { - console.log(e) removeAuthToken() next({ path: `${WhiteListPage.LOGIN_PATH}?redirect=/${to.path}` }) } @@ -54,6 +58,7 @@ const guard = (router: Router) => { } else { // 如果不在白名单 if (whiteList.indexOf(to.path) !== -1) { + console.log(123) next() } else { next({ path: WhiteListPage.LOGIN_PATH }) diff --git a/resources/admin/router/index.ts b/resources/admin/router/index.ts index 6a5f08c..42c058d 100644 --- a/resources/admin/router/index.ts +++ b/resources/admin/router/index.ts @@ -43,12 +43,7 @@ const defaultRoutes: RouteRecordRaw[] = [ name: 'login', meta: { title: '登录' }, component: () => import('/admin/views/login/index.vue'), - }, - // 未定义路有重定向到 404 - { - path: '/:pathMatch(.*)*', - redirect: '/404', - }, + } ] const routes = constantRoutes.concat(defaultRoutes)