diff --git a/src/router/index.js b/src/router/index.js index f2a6ed3f6c6a3f95298818378e61194b7378121f..447635e6eb06e80563564b190199f2fd8b6b0458 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -11,19 +11,10 @@ import {beforeEach, afterEach} from './scrollBehavior'; //系统路由 const routes = systemRouter -//系统特殊路由 -const routes_404 = { - path: "/:pathMatch(.*)*", - hidden: true, - component: () => import(/* webpackChunkName: "404" */ '@/layout/other/404'), -} -let routes_404_r = ()=>{} - const router = createRouter({ history: createWebHashHistory(), routes: routes }) - //设置标题 document.title = config.APP_NAME @@ -41,8 +32,6 @@ router.beforeEach(async (to, from, next) => { if(to.path === "/login"){ //删除路由(替换当前layout路由) router.addRoute(routes[0]) - //删除路由(404) - routes_404_r() isGetRouter = false; next(); return false; @@ -77,13 +66,16 @@ router.beforeEach(async (to, from, next) => { menuRouter.forEach(item => { router.addRoute("layout", item) }) - routes_404_r = router.addRoute(routes_404) + if (to.matched.length == 0) { router.push(to.fullPath); } isGetRouter = true; + beforeEach(to, from); + next({ ...to, replace: true }); + return false; } - beforeEach(to, from) + next(); }); diff --git a/src/router/systemRouter.js b/src/router/systemRouter.js index fd51a958e70a9fdf06914d82253e6560ced5769e..64168400c26400d0956e29db30ee79f277ffb0e1 100644 --- a/src/router/systemRouter.js +++ b/src/router/systemRouter.js @@ -2,6 +2,11 @@ import config from "@/config" //系统路由 const routes = [ + { + path: "/:pathMatch(.*)*", + hidden: true, + component: () => import(/* webpackChunkName: "404" */ '@/layout/other/404'), + }, { name: "layout", path: "/",