liweilong
2020-10-30 f72166516630670cceae97ed636500aedcb4bcb5
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
import Vue from 'vue'
import Router from 'vue-router'
 
Vue.use(Router)
 
/* Layout */
import Layout from '@/layout'
 
import demo_router from './demo_router'
import system_router from './system_router'
import op_router from './op_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,
  demo_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()
 
// 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