ebb9dc515df4786240ca5e6998ca40b12243044e.svn-base 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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' 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: 'Dashboard',
  47. // component: () => import('@/views/dashboard/editor/index'),
  48. component: () => import('@/views/dashboard/index'),
  49. meta: { title: '首页', icon: '首页', affix: true }
  50. }]
  51. },
  52. {
  53. path: '/changpwd',
  54. component: Layout,
  55. redirect: '/changpwd',
  56. children: [{
  57. path: 'changpwd',
  58. name: 'Changpwd',
  59. component: () => import('@/views/changpwd/changpwd/index'),
  60. meta: { title: '修改密码', icon: '修改密码', affix: false }
  61. }]
  62. }
  63. ]
  64. /**
  65. * asyncRoutes
  66. * the routes that need to be dynamically loaded based on user roles
  67. */
  68. export const asyncRoutes = [
  69. {
  70. path: '/nested',
  71. component: Layout,
  72. redirect: '/nested/menu1',
  73. name: 'Nested',
  74. meta: {
  75. title: 'Nested',
  76. icon: 'nested'
  77. },
  78. children: [
  79. {
  80. path: 'menu1',
  81. component: () => import('@/views/nested/menu1/index'), // Parent router-view
  82. name: 'Menu1',
  83. meta: { title: 'Menu1' },
  84. children: [
  85. {
  86. path: 'menu1-1',
  87. component: () => import('@/views/nested/menu1/menu1-1'),
  88. name: 'Menu1-1',
  89. meta: { title: 'Menu1-1' }
  90. },
  91. {
  92. path: 'menu1-2',
  93. component: () => import('@/views/nested/menu1/menu1-2'),
  94. name: 'Menu1-2',
  95. meta: { title: 'Menu1-2' },
  96. children: [
  97. {
  98. path: 'menu1-2-1',
  99. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  100. name: 'Menu1-2-1',
  101. meta: { title: 'Menu1-2-1' }
  102. },
  103. {
  104. path: 'menu1-2-2',
  105. component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  106. name: 'Menu1-2-2',
  107. meta: { title: 'Menu1-2-2' }
  108. }
  109. ]
  110. },
  111. {
  112. path: 'menu1-3',
  113. component: () => import('@/views/nested/menu1/menu1-3'),
  114. name: 'Menu1-3',
  115. meta: { title: 'Menu1-3' }
  116. }
  117. ]
  118. },
  119. {
  120. path: 'menu2',
  121. component: () => import('@/views/nested/menu2/index'),
  122. meta: { title: 'menu2' }
  123. }
  124. ]
  125. },
  126. {
  127. path: 'external-link',
  128. component: Layout,
  129. children: [
  130. {
  131. path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  132. meta: { title: 'External Link', icon: 'link' }
  133. }
  134. ]
  135. },
  136. // 404 page must be placed at the end !!!
  137. { path: '*', redirect: '/404', hidden: true }
  138. ]
  139. const createRouter = () => new Router({
  140. // mode: 'history', // require service support
  141. scrollBehavior: () => ({ y: 0 }),
  142. routes: constantRoutes
  143. })
  144. const router = createRouter()
  145. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  146. export function resetRouter() {
  147. const newRouter = createRouter()
  148. router.matcher = newRouter.matcher // reset router
  149. }
  150. export default router