zj
2024-06-03 e02a610447cb4c55c29eeb4441372d4a47b913b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import Vue from 'vue'
import Router from 'vue-router'
import { constantRouterMap } from '@/config/router.config'
 
// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
 
Vue.use(Router)
 
const createRouter = () =>
  new Router({
    mode: 'hash',
    routes: constantRouterMap
  })
 
 
 
 
const router = createRouter()
 
// 定义一个resetRouter 方法,在退出登录后或token过期后 需要重新登录时,调用即可
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
router.$addRoutes = (params) => {
  router.matcher = new Router({mode: 'hash'}).matcher;
  router.addRoutes(params)
}
 
 
 
// 公共路由
const constantRoutes = [
    {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/Workplace'),
        meta: {
            title: '工作台',
        },
        hidden: true
    },
    {
        path: '/404',
        component: () => import('@/views/exception/404'),
        meta: {
            title: '404',
        },
        hidden: true
    },
];
// // 清空路由表
// export const asyncRouterMap = [];
 
// const createRouter = () =>
//     new Router({
//         // mode: 'history', // require service support
//         scrollBehavior: () => ({ y: 0 }),
//         routes: constantRoutes,
//     });
 
// const router = createRouter();
 
// // 重置路由,防止重复添加崩溃
// export function resetRouter() {
//   const newRouter = createRouter()
//   router.matcher = newRouter.matcher // reset router
// }
export default router