index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Vue from "vue";
  2. import VueRouter from "vue-router";
  3. import Home from "../views/home/Index.vue";
  4. Vue.use(VueRouter);
  5. const createRouter = () =>
  6. new VueRouter({
  7. mode: "history",
  8. base: process.env.BASE_URL,
  9. scrollBehavior: () => ({ y: 0 }),
  10. routes: [
  11. {
  12. path: "/",
  13. redirect: "/login",
  14. },
  15. {
  16. path: "/home",
  17. redirect: "/home/cockpitManage",
  18. name: "home",
  19. component: Home,
  20. children: [
  21. // 驾驶舱
  22. {
  23. id: 1,
  24. path: "cockpitManage",
  25. name: "驾驶舱",
  26. iconName: "gps",
  27. component: () =>
  28. import(
  29. // /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/Index.vue"
  30. /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/HD.vue"
  31. ),
  32. },
  33. {
  34. // 电子地图
  35. id: 11,
  36. path: "/home/cockpitManage/electronic-map",
  37. name: "电子地图",
  38. component: () =>
  39. import(
  40. /*webpackChunkName:'home-cockpitManage'*/ "../views/admin/cockpitManage/electronicMap.vue"
  41. ),
  42. },
  43. // {
  44. // id: 11,
  45. // path: "/home/performance/customAnalysis",
  46. // name: "自定义分析",
  47. // component: () =>
  48. // import(
  49. // /*webpackChunkName:'home-cockpitManage'*/ "../views/performance/customAnalysis.vue"
  50. // ),
  51. // },
  52. // {
  53. // id: 11,
  54. // path: "/home/performance/luckySheet",
  55. // name: "自定义分析表格编辑",
  56. // component: () =>
  57. // import(
  58. // /*webpackChunkName:'home-cockpitManage'*/ "../views/performance/components/custonAsCom/luckySheet.vue"
  59. // ),
  60. // },
  61. ],
  62. },
  63. {
  64. path: "/login",
  65. name: "login",
  66. component: () => import("../views/login/Index.vue"),
  67. },
  68. {
  69. path: "/transition",
  70. name: "transition",
  71. component: () => import("../views/transition/index.vue"),
  72. },
  73. // 404 Page Not Found
  74. // {
  75. // path: "*",
  76. // name: "NotFound",
  77. // component: () => import("../views/error/404.vue"),
  78. // },
  79. ],
  80. });
  81. const router = createRouter();
  82. const originalPush = VueRouter.prototype.push;
  83. VueRouter.prototype.push = function push(location) {
  84. return originalPush.call(this, location).catch((err) => err);
  85. };
  86. // 重置路由
  87. export function resetRouter() {
  88. const newRouter = createRouter();
  89. router.matcher = newRouter.matcher; // reset router
  90. }
  91. router.beforeEach((to, from, next) => {
  92. if (to.matched.length === 0) {
  93. return next("/login");
  94. } else {
  95. next();
  96. }
  97. });
  98. export default router;