index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /**
  7. * Note: sub-menu only appear when route children.length >= 1
  8. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  9. *
  10. * hidden: true if set true, item will not show in the sidebar(default is false)
  11. * alwaysShow: true if set true, will always show the root menu
  12. * if not set alwaysShow, when item has more than one children route,
  13. * it will becomes nested mode, otherwise not show the root menu
  14. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  15. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  16. * meta : {
  17. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  18. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  19. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  20. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  21. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  22. }
  23. */
  24. /**
  25. * constantRoutes
  26. * a base page that does not have permission requirements
  27. * all roles can be accessed
  28. */
  29. export const constantRoutes = [
  30. {
  31. path: '/login',
  32. component: () => import('@/views/login/index'),
  33. hidden: true
  34. },
  35. {
  36. path: '/404',
  37. component: () => import('@/views/404'),
  38. hidden: true
  39. },
  40. ]
  41. export const asyncRoutes = [
  42. {
  43. path: '/',
  44. component: Layout,
  45. redirect: '/dashboard',
  46. children: [{
  47. path: 'dashboard',
  48. name: 'Dashboard',
  49. component: () => import('@/views/dashboard/index'),
  50. meta: { title: '工作台', icon: 'dashboard' }
  51. }]
  52. },
  53. {
  54. path: '/project',
  55. component: Layout,
  56. redirect: '/project/list',
  57. meta: { title: '项目管理', icon: 'table', roleValue: 'project_list_show'},
  58. children: [{
  59. path: 'list',
  60. name: 'project',
  61. component: () => import('@/views/project/index'),
  62. meta: { title: '项目列表', roleValue: 'project_list_show' }
  63. }]
  64. },
  65. {
  66. path: '/department',
  67. component: Layout,
  68. redirect: '/department/list',
  69. meta: { title: '部门管理', icon: 'el-icon-s-check', roleValue: 'department_list_show' },
  70. children: [{
  71. path: 'list',
  72. name: 'department',
  73. component: () => import('@/views/department/index'),
  74. meta: { title: '部门列表', roleValue: 'department_list_show' }
  75. }]
  76. },
  77. {
  78. path: '/roles',
  79. component: Layout,
  80. redirect: '/roles/list',
  81. meta: { title: '角色管理', icon: 'peoples', roleValue: 'roles_list_show' },
  82. children: [{
  83. path: 'list',
  84. name: 'roles',
  85. component: () => import('@/views/roles/index'),
  86. meta: { title: '角色列表', roleValue: 'roles_list_show' }
  87. }]
  88. },
  89. {
  90. path: '/user',
  91. component: Layout,
  92. redirect: '/user/list',
  93. meta: { title: '用户管理', icon: 'user', roleValue: 'user_list_show' },
  94. children: [{
  95. path: 'list',
  96. name: 'user',
  97. component: () => import('@/views/user/index'),
  98. meta: { title: '用户列表', roleValue: 'user_list_show' }
  99. }]
  100. },
  101. {
  102. path: '/icon',
  103. component: Layout,
  104. redirect: '/icon/list',
  105. hidden: true,
  106. children: [{
  107. path: 'list',
  108. name: 'icon',
  109. component: () => import('@/views/icons/index'),
  110. meta: { title: 'icon', icon: 'el-icon-s-grid' }
  111. }]
  112. },
  113. { path: '*', redirect: '/404', hidden: true }
  114. ]
  115. const createRouter = () => new Router({
  116. // mode: 'history', // require service support
  117. mode: 'history',
  118. scrollBehavior: () => ({ y: 0 }),
  119. routes: constantRoutes
  120. })
  121. const router = createRouter()
  122. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  123. export function resetRouter() {
  124. const newRouter = createRouter()
  125. router.matcher = newRouter.matcher // reset router
  126. }
  127. export default router