index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. /* Layout */
  4. import Layout from '@/layout'
  5. Vue.use(Router)
  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' 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: '/404',
  32. component: () => import('@/views/404'),
  33. hidden: true
  34. },
  35. {
  36. path: '/',
  37. component: Layout,
  38. redirect: '/dashboard',
  39. children: [{
  40. path: 'dashboard',
  41. name: 'Dashboard',
  42. component: () => import('@/views/dashboard/index'),
  43. meta: { title: '首页', icon: 'dashboard' }
  44. }]
  45. },
  46. {
  47. path: '/generate',
  48. component: Layout,
  49. meta: { title: '生成代码', icon: 'form' },
  50. redirect: '/generate/config',
  51. children: [
  52. {
  53. path: 'config',
  54. name: 'Config',
  55. component: () => import('@/views/generate/index'),
  56. meta: { title: '生成代码' }
  57. },
  58. {
  59. path: 'result/:config',
  60. name: 'Result',
  61. component: () => import('@/views/generate/result'),
  62. meta: { title: '生成结果' },
  63. hidden: true
  64. }
  65. ]
  66. },
  67. {
  68. path: '/group',
  69. component: Layout,
  70. meta: { title: '模板组管理', icon: 'example' },
  71. redirect: '/group/list',
  72. children: [
  73. {
  74. path: 'list',
  75. name: 'List',
  76. component: () => import('@/views/group/index'),
  77. meta: { title: '模板组管理' }
  78. }
  79. ]
  80. },
  81. {
  82. path: '/template',
  83. component: Layout,
  84. meta: { title: '模板管理', icon: 'table' },
  85. redirect: '/template/list',
  86. children: [
  87. {
  88. path: 'list',
  89. name: 'List',
  90. component: () => import('@/views/template/index'),
  91. meta: { title: '模板管理' }
  92. },
  93. {
  94. path: 'edit/:id(\\d+)',
  95. name: 'Edit',
  96. component: () => import('@/views/template/edit'),
  97. meta: { 'title': '编辑模板' },
  98. hidden: true
  99. }
  100. ]
  101. },
  102. // 404 page must be placed at the end !!!
  103. { path: '*', redirect: '/404', hidden: true }
  104. ]
  105. const createRouter = () => new Router({
  106. // mode: 'history', // require service support
  107. scrollBehavior: () => ({ y: 0 }),
  108. routes: constantRoutes
  109. })
  110. const router = createRouter()
  111. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  112. export function resetRouter() {
  113. const newRouter = createRouter()
  114. router.matcher = newRouter.matcher // reset router
  115. }
  116. export default router