jazzzone
2022-03-05 f2a2b4a4258cc1c88b897024bc5c49f31273c0ca
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import Vue from 'vue'
import Router from 'vue-router'
 
Vue.use(Router)
 
/* Layout */
import Layout from '@/layout'
 
// import demo_router from './demo_router'
import sms_router from './sms_router'
// import system_router from './system_router'
// import op_router from './op_router'
// import agreement_router from './agreement_router'
 
/**
 * 注:子菜单只出现在路线子时。长度> = 1
 * 详细信息见: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   项目将不会在侧边栏显示(默认为false)
 * alwaysShow: true               如果设置为true,将始终显示根菜单
 *                                如果没有设置alwaysShow,当项目有多个子路径时,
 *                                它将变成嵌套模式,否则不会显示根菜单
 * redirect: noRedirect           如果设置了noRedirect将不会在面包屑中重定向
 * name:'router-name'              <keep-alive>使用该名称(必须设置!!)
 * meta : {
    roles: ['admin','editor']    控制页面角色(可以设置多个角色)s)
    title: 'title'               在侧边栏和面包屑中显示的名称(推荐设置)
    icon: 'svg-name'/'el-icon-x' 图标显示在侧边栏
    breadcrumb: false            项目将隐藏在breadcrumb中(默认为true)
    activeMenu: '/example/list'  如果设置路径,侧边栏将突出显示您设置的路径
  }
 */
 
/**
 * constantRoutes
 * 没有权限要求的基本页面
 * 所有角色都可以访问
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/pages/login/index'),
    hidden: true
  },
 
  {
    path: '/404',
    component: () => import('@/pages/404'),
    hidden: true
  },
 
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/pages/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
 
  // system_router,
  sms_router,
  // demo_router,
  // agreement_router,
 
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: '外链', icon: 'link' },
  //       auth: 'external_link'
  //     }
  //   ]
  // },
 
  // {
  //   path: '/demo',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '/demo',
  //       component: () => import('@/pages/demo/demo'), // Parent router-view
  //       name: 'demo',
  //       meta: { title: 'demo', icon: 'example' }
  //     }
  //   ]
  // },
 
  // op_router,
 
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
 
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
 
const router = createRouter()
 
// 守卫,处理keepAlive周期,用isBack标记是否属于从属页面后退
router.beforeEach(function(to, from, next) {
  // 判断是否从从属页面后退
  if (to.meta.keepAlive && from.meta.activeMenu === to.path) {
    to.meta.isBack = true
  } else {
    to.meta.isBack = false
  }
  next(true)
})
 
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
 
export default router