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