index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. // import consoleRouter from './modules/console'
  7. // import systemRouter from './modules/system'
  8. // import dataExchangeRouter from "./modules/dataexchange"
  9. // import uploadRouter from './modules/uploadFile';
  10. /**
  11. * Note: sub-menu only appear when route children.length >= 1
  12. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  13. *
  14. * hidden: true if set true, item will not show in the sidebar(default is false)
  15. * alwaysShow: true if set true, will always show the root menu
  16. * if not set alwaysShow, when item has more than one children route,
  17. * it will becomes nested mode, otherwise not show the root menu
  18. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  19. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  20. * meta : {
  21. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  22. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  23. icon: 'svg-name' the icon show in the sidebar
  24. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  25. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  26. }
  27. */
  28. /**
  29. * constantRoutes
  30. * a base page that does not have permission requirements
  31. * all roles can be accessed
  32. */
  33. export const constantRoutes = [
  34. {
  35. path: '/login',
  36. component: () => import('@/views/login/index'),
  37. hidden: true
  38. },
  39. {
  40. path: '',
  41. component: Layout,
  42. redirect: '/dashboard',
  43. children: [{
  44. path: '/dashboard',
  45. name: '首页',
  46. component: () => import('@/views/dashboard/index'),
  47. meta: {title: '首页', icon: 'dashboard', affix: true}
  48. }]
  49. },
  50. // {
  51. // path: '/sysManager',
  52. // component: Layout,
  53. // redirect: '/sysManager',
  54. // meta: {
  55. // title: '系统管理'
  56. // },
  57. // children: [
  58. // {
  59. // path: 'userManager',
  60. // name: '用户管理',
  61. // component: () => import('@/views/sysManager/userManager/index'),
  62. // meta: {title: '用户管理'}
  63. // },
  64. // {
  65. // path: 'sysParameter',
  66. // name: '参数管理',
  67. // component: () => import('@/views/sysManager/sysParameter/index'),
  68. // meta: {title: '参数管理'}
  69. // }
  70. // ,
  71. // {
  72. // path: 'sysMenu',
  73. // name: '菜单管理',
  74. // component: () => import('@/views/sysManager/sysMenu/index'),
  75. // meta: {title: '菜单管理'}
  76. // }
  77. // ]
  78. // },
  79. {
  80. path: '/404',
  81. component: () => import('@/views/404'),
  82. hidden: true
  83. },
  84. {
  85. path: '/user',
  86. component: Layout,
  87. hidden: true,
  88. redirect: 'noredirect',
  89. children: [
  90. {
  91. path: 'profile',
  92. component: () => import('@/views/sysManager/userManager/profile/index'),
  93. name: 'Profile',
  94. meta: {title: '个人中心', icon: 'user'}
  95. }
  96. ]
  97. }
  98. ]
  99. // 动态路由,基于用户权限动态去加载
  100. export const dynamicRoutes = [
  101. ]
  102. const createRouter = () => new Router({
  103. mode: 'history', // require service support
  104. scrollBehavior: () => ({y: 0}),
  105. routes: constantRoutes
  106. })
  107. const router = createRouter()
  108. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  109. export function resetRouter() {
  110. const newRouter = createRouter()
  111. router.matcher = newRouter.matcher // reset router
  112. }
  113. const originalPush = Router.prototype.push
  114. Router.prototype.push = function push(location, onResolve, onReject) {
  115. if (onResolve || onReject)
  116. return originalPush.call(this, location, onResolve, onReject)
  117. return originalPush.call(this, location).catch((err) => err)
  118. }
  119. export default router