index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. path: '/',
  42. component: Layout,
  43. redirect: '/dashboard',
  44. children: [{
  45. path: 'dashboard',
  46. name: '我的工作台',
  47. component: () => import('@/views/dashboard/index'),
  48. meta: {title: '我的工作台', icon: 'dashboard'}
  49. }]
  50. },
  51. {
  52. path: '/user',
  53. component: Layout,
  54. hidden: true,
  55. redirect: 'noredirect',
  56. children: [
  57. {
  58. path: 'profile',
  59. component: () => import('@/views/system/profile/index'),
  60. name: 'Profile',
  61. meta: { title: '个人中心', icon: 'user' }
  62. }
  63. ]
  64. }
  65. ]
  66. // 动态路由,基于用户权限动态去加载
  67. export const dynamicRoutes = [
  68. {path: '*', redirect: '/404', hidden: true}
  69. ]
  70. // 防止连续点击多次路由报错
  71. let routerPush = Router.prototype.push;
  72. let routerReplace = Router.prototype.replace;
  73. // push
  74. Router.prototype.push = function push(location) {
  75. return routerPush.call(this, location).catch(err => err)
  76. }
  77. // replace
  78. Router.prototype.replace = function push(location) {
  79. return routerReplace.call(this, location).catch(err => err)
  80. }
  81. export default new Router({
  82. base: process.env.VUE_APP_CONTEXT_PATH,
  83. mode: 'history', // 去掉url中的#
  84. scrollBehavior: () => ({ y: 0 }),
  85. routes: constantRoutes
  86. })
  87. // const createRouter = () => new Router({
  88. // // mode: 'history', // require service support
  89. // scrollBehavior: () => ({y: 0}),
  90. // routes: constantRoutes
  91. // })
  92. //
  93. // const router = createRouter()
  94. //
  95. // // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  96. // export function resetRouter() {
  97. // const newRouter = createRouter()
  98. // router.matcher = newRouter.matcher // reset router
  99. // }
  100. //
  101. // export default router