From 2e3dc366e857e052ce6492adc67f76bfd9f7dbea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chuailei000=E2=80=9D?= <2280131253@qq.com> Date: Mon, 14 Mar 2022 11:47:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E5=90=8E=E9=A1=B5=E9=9D=A2=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=88=B0404=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 5 ----- src/utils/startup.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 009024bec..b45b79581 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -69,11 +69,6 @@ export const constantRoutes = [ component: () => import('@/views/404'), hidden: true }, - { - path: '*', - redirect: '/404', - hidden: true - }, ...commonRoutes ] diff --git a/src/utils/startup.js b/src/utils/startup.js index 6b8bd699e..fe3b399df 100644 --- a/src/utils/startup.js +++ b/src/utils/startup.js @@ -81,10 +81,16 @@ export async function generatePageRoutes({ to, from, next }) { try { // try get user profile // generate accessible routes map based on roles - const accessRoutes = await store.dispatch('permission/generateRoutes', { to, from }) + let accessRoutes = await store.dispatch('permission/generateRoutes', { to, from }) + // Incorrect route, jump to 404 + accessRoutes = [...accessRoutes, { + path: '*', + redirect: '/404', + hidden: true + }] // dynamically add accessible routes - Vue.$log.debug('All routes: ', accessRoutes) + Vue.$log.debug('All routes:', accessRoutes) router.addRoutes(accessRoutes) await store.dispatch('permission/generateViewRoutes', { to, from })