long
2022-01-21 958f5a5abc6b5d4efee768d0b181078c25d4199e
提交 | 用户 | age
2a61f6 1 import Vue from 'vue'
L 2 import Router from 'vue-router'
3
4 Vue.use(Router)
5
6 /* Layout */
7 import Layout from '@/layout'
8
9 import demo_router from './demo_router'
10 import system_router from './system_router'
11 import op_router from './op_router'
133cfa 12 import agreement_router from './agreement_router'
2a61f6 13
L 14 /**
15  * 注:子菜单只出现在路线子时。长度> = 1
16  * 详细信息见: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
17  *
18  * hidden: true                   项目将不会在侧边栏显示(默认为false)
19  * alwaysShow: true               如果设置为true,将始终显示根菜单
20  *                                如果没有设置alwaysShow,当项目有多个子路径时,
21  *                                它将变成嵌套模式,否则不会显示根菜单
22  * redirect: noRedirect           如果设置了noRedirect将不会在面包屑中重定向
23  * name:'router-name'              <keep-alive>使用该名称(必须设置!!)
24  * meta : {
25     roles: ['admin','editor']    控制页面角色(可以设置多个角色)s)
26     title: 'title'               在侧边栏和面包屑中显示的名称(推荐设置)
27     icon: 'svg-name'/'el-icon-x' 图标显示在侧边栏
28     breadcrumb: false            项目将隐藏在breadcrumb中(默认为true)
29     activeMenu: '/example/list'  如果设置路径,侧边栏将突出显示您设置的路径
30   }
31  */
32
33 /**
34  * constantRoutes
35  * 没有权限要求的基本页面
36  * 所有角色都可以访问
37  */
38 export const constantRoutes = [
39   {
40     path: '/login',
41     component: () => import('@/pages/login/index'),
42     hidden: true
43   },
44
45   {
46     path: '/404',
47     component: () => import('@/pages/404'),
48     hidden: true
49   },
50
51   {
52     path: '/',
53     component: Layout,
54     redirect: '/dashboard',
55     children: [{
56       path: 'dashboard',
57       name: '首页',
58       component: () => import('@/pages/dashboard/index'),
59       meta: { title: '首页', icon: 'dashboard' }
60     }]
61   },
62
63   system_router,
64   demo_router,
133cfa 65   agreement_router,
2a61f6 66
L 67   {
68     path: 'external-link',
69     component: Layout,
70     children: [
71       {
72         path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
73         meta: { title: '外链', icon: 'link' },
74         auth: 'external_link'
75       }
76     ]
77   },
78
79   // {
80   //   path: '/demo',
81   //   component: Layout,
82   //   children: [
83   //     {
84   //       path: '/demo',
85   //       component: () => import('@/pages/demo/demo'), // Parent router-view
86   //       name: 'demo',
87   //       meta: { title: 'demo', icon: 'example' }
88   //     }
89   //   ]
90   // },
91
92   op_router,
93
94   // 404 page must be placed at the end !!!
95   { path: '*', redirect: '/404', hidden: true }
96 ]
97
98 const createRouter = () => new Router({
99   // mode: 'history', // require service support
100   scrollBehavior: () => ({ y: 0 }),
101   routes: constantRoutes
102 })
103
104 const router = createRouter()
105
1776f0 106 // 守卫,处理keepAlive周期,用isBack标记是否属于从属页面后退
L 107 router.beforeEach(function(to, from, next) {
108   // 判断是否从从属页面后退
109   if (to.meta.keepAlive && from.meta.activeMenu === to.path) {
110     to.meta.isBack = true
111   } else {
112     to.meta.isBack = false
113   }
114   next(true)
115 })
116
2a61f6 117 // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
L 118 export function resetRouter() {
119   const newRouter = createRouter()
120   router.matcher = newRouter.matcher // reset router
121 }
122
123 export default router