diff --git a/src/router/index.js b/src/router/index.js index cb33b4c5..2d705237 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -9,10 +9,8 @@ import '@/assets/styles/nprogress.scss' import { useNProgress } from '@vueuse/integrations/useNProgress' const { isLoading } = useNProgress() -import generatedRoutes from 'virtual:generated-pages' - // 路由相关数据 -import { constantRoutes, asyncRoutes, notFoundRoute } from './routes' +import { constantRoutes, asyncRoutes } from './routes' const router = createRouter({ history: createWebHashHistory(), @@ -87,18 +85,18 @@ router.beforeEach(async(to, from, next) => { removeRoutes.push(router.addRoute(route)) } }) - if (settingsStore.app.routeBaseOn === 'filesystem') { - const otherRoutes = generatedRoutes.filter(item => item.meta?.constant !== true && item.meta?.layout === false) - otherRoutes.length && removeRoutes.push(router.addRoute(...otherRoutes)) - } else { + if (settingsStore.app.routeBaseOn !== 'filesystem') { routeStore.flatSystemRoutes.forEach(route => { removeRoutes.push(router.addRoute(route)) }) - removeRoutes.push(router.addRoute(notFoundRoute)) } // 记录的 accessRoutes 路由数据,在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除 routeStore.setCurrentRemoveRoutes(removeRoutes) - next({ ...to, replace: true }) + next({ + path: to.fullPath, + query: to.query, + replace: true + }) } } else { if (to.name != 'login') { diff --git a/src/router/routes.js b/src/router/routes.js index 6d656003..3a2f8131 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -14,6 +14,14 @@ let constantRoutes = [ meta: { title: '登录' } + }, + { + path: '/:all(.*)*', + name: 'notFound', + component: () => import('@/views/[...all].vue'), + meta: { + title: '找不到页面' + } } ] @@ -122,19 +130,8 @@ if (useSettingsStore(pinia).app.routeBaseOn === 'filesystem') { })) } -// 404路由 -const notFoundRoute = { - path: '/:all(.*)*', - name: 'notFound', - component: () => import('@/views/[...all].vue'), - meta: { - title: '找不到页面' - } -} - export { constantRoutes, systemRoutes, - asyncRoutes, - notFoundRoute + asyncRoutes } diff --git a/src/views/[...all].vue b/src/views/[...all].vue index ba81899f..289e4920 100644 --- a/src/views/[...all].vue +++ b/src/views/[...all].vue @@ -3,6 +3,7 @@ name: 'notFound', meta: { title: "找不到页面", + constant: true, layout: false } }