import Vue from "vue"; import VueRouter from "vue-router"; import Home from "../views/home/Index.vue"; Vue.use(VueRouter); const createRouter = () => new VueRouter({ mode: "history", base: process.env.BASE_URL, scrollBehavior: () => ({ y: 0 }), routes: [ { path: "/", redirect: "/login", }, { path: "/home", redirect: "/home/cockpitManage", name: "home", component: Home, children: [ // 驾驶舱 { id: 1, path: "cockpitManage", name: "驾驶舱", iconName: "gps", component: () => import( /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/Index.vue" // /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/HD.vue" //华电选择这个 ), }, { // 电子地图 id: 11, path: "/home/cockpitManage/electronic-map", name: "电子地图", component: () => import( /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/electronicMap.vue" ), }, // { // id: 11, // path: "/home/performance/customAnalysis", // name: "自定义分析", // component: () => // import( // /*webpackChunkName:'home-cockpitManage'*/ "../views/performance/customAnalysis.vue" // ), // }, // { // id: 11, // path: "/home/performance/luckySheet", // name: "自定义分析表格编辑", // component: () => // import( // /*webpackChunkName:'home-cockpitManage'*/ "../views/performance/components/custonAsCom/luckySheet.vue" // ), // }, ], }, { path: "/login", name: "login", component: () => import("../views/login/Index.vue"), }, { path: "/transition", name: "transition", component: () => import("../views/transition/index.vue"), }, // 404 Page Not Found // { // path: "*", // name: "NotFound", // component: () => import("../views/error/404.vue"), // }, ], }); const router = createRouter(); const originalPush = VueRouter.prototype.push; VueRouter.prototype.push = function push(location) { return originalPush.call(this, location).catch((err) => err); }; // 重置路由 export function resetRouter() { const newRouter = createRouter(); router.matcher = newRouter.matcher; // reset router } router.beforeEach((to, from, next) => { if (to.matched.length === 0) { return next("/login"); } else { next(); } }); export default router;