import { createRouter, createWebHashHistory, Router } from "vue-router"; import Layout from "@/layout"; import { RouterTy } from "~/router"; import routesOne from "./routes/routes-file-one"; import routesTwo from "./routes/routes-file-two"; import routesThree from "./routes/routes-file-three"; import routesFour from "./routes/routes-file-four"; import routesFive from "./routes/routes-file-five"; import routesSix from "./routes/routes-file-six"; const routesPush = (arr, routes) => { if (!Array.isArray(arr)) return "请传入数组格式路由表"; for (let i = 0; i < arr.length; i++) { routes.push(arr[i]); } }; export const constantRoutes: RouterTy = [ { path: "/redirect", component: Layout, hidden: true, children: [ { path: "/redirect/:path(.*)", component: () => import("@/views/redirect"), }, ], }, { path: "/login", component: () => import("@/views/login/Login.vue"), hidden: true, }, { path: "/404", component: () => import("@/views/error-page/404.vue"), hidden: true, }, { path: "/401", component: () => import("@/views/error-page/401.vue"), hidden: true, }, ]; /** * asyncRoutes * the routes that need to be dynamically loaded based on user roles */ export const asyncRoutes: RouterTy = [ // 404 page must be placed at the end !!! // using pathMatch install of "*" in vue-router 4.0 { path: "/:pathMatch(.*)", redirect: "/404", hidden: true }, ]; // 插入路由 routesPush( [ ...routesOne, ...routesTwo, ...routesThree, ...routesFour, ...routesFive, ...routesSix, ], asyncRoutes ); const router: Router = createRouter({ history: createWebHashHistory(), scrollBehavior: () => ({ top: 0 }), routes: constantRoutes, }); // export function resetRouter() { // const newRouter = createRouter({ // history: createWebHashHistory(), // scrollBehavior: () => ({ top: 0 }), // routes: constantRoutes // }) // } export default router;