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