index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. /* Layout */
  5. import Layout from '@/layout'
  6. /* Router Modules */
  7. import articleRouter from '@/router/modules/article'
  8. import atlasRouter from '@/router/modules/atlas'
  9. import bonusRouter from '@/router/modules/bonus'
  10. import configRouter from '@/router/modules/config'
  11. import financeRouter from '@/router/modules/finance'
  12. import profileRouter from '@/router/modules/profile'
  13. import shopRouter from '@/router/modules/shop'
  14. import userRouter from '@/router/modules/user'
  15. import chartsRouter from './modules/charts'
  16. import componentsRouter from './modules/components'
  17. import nestedRouter from './modules/nested'
  18. import tableRouter from './modules/table'
  19. import refactorRouter from '@/router/modules/refactor'
  20. import purchaseRoutes from '@/ui-refactor/views/purchase/routes'
  21. import { guestRoutes } from '@/ui-refactor/views/guest-shop/routes'
  22. /**
  23. * Note: sub-menu only appear when route children.length >= 1
  24. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  25. *
  26. * hidden: true if set true, item will not show in the sidebar(default is false)
  27. * alwaysShow: true if set true, will always show the root menu
  28. * if not set alwaysShow, when item has more than one children route,
  29. * it will becomes nested mode, otherwise not show the root menu
  30. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  31. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  32. * meta : {
  33. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  34. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  35. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  36. noCache: true if set true, the page will no be cached(default is false)
  37. affix: true if set true, the tag will affix in the tags-view
  38. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  39. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  40. }
  41. */
  42. /**
  43. * constantRoutes
  44. * a base page that does not have permission requirements
  45. * all roles can be accessed
  46. */
  47. export const constantRoutes = [
  48. {
  49. path: '/redirect',
  50. component: Layout,
  51. hidden: true,
  52. children: [
  53. {
  54. path: '/redirect/:path(.*)',
  55. component: () => import('@/views/redirect/index')
  56. }
  57. ]
  58. },
  59. {
  60. path: '/login',
  61. component: () => import('@/views/login/index'),
  62. hidden: true,
  63. meta: { title: '会员管理系统' }
  64. },
  65. {
  66. path: '/auth-redirect',
  67. component: () => import('@/views/login/auth-redirect'),
  68. hidden: true
  69. },
  70. {
  71. path: '/login-by-backend',
  72. component: () => import('@/views/login/login-by-backend'),
  73. name: 'login-by-backend'
  74. },
  75. {
  76. path: '/404',
  77. component: () => import('@/views/error-page/404'),
  78. hidden: true
  79. },
  80. {
  81. path: '/401',
  82. component: () => import('@/views/error-page/401'),
  83. hidden: true
  84. },
  85. {
  86. path: '/',
  87. component: () => import('@/ui-refactor/index.vue'),
  88. redirect: '/dashboard/index',
  89. children: [
  90. ...purchaseRoutes,
  91. ...guestRoutes,
  92. {
  93. path: 'dashboard/member-welcome-pack',
  94. component: () => import('@/ui-refactor/views/welcome-pack/MemberWelcomePack.vue'),
  95. props: { mode: 'member' },
  96. name: 'MemberWelcomePack',
  97. meta: {
  98. title: 'Member Welcome Pack',
  99. publicLayout: {
  100. hero: {
  101. breadcrumbs: [
  102. { text: 'My Account', to: '/dashboard/index' },
  103. { text: 'Member Welcome Pack' }
  104. ],
  105. titleParts: [{ text: 'Member ' }, { text: 'Welcome Pack.', accent: true }],
  106. subtitle:
  107. 'Continue your order with your current member info. Referrer fields are pre-filled with your profile, and payment runs through the unified checkout flow.'
  108. }
  109. }
  110. }
  111. },
  112. {
  113. path: 'dashboard/index',
  114. alias: '/dashboard/index/dashboard',
  115. component: () => import('@/ui-refactor/views/account/AccountPage.vue'),
  116. name: 'Dashboard',
  117. meta: { title: 'dashboard', icon: 'dashboard', affix: true }
  118. },
  119. {
  120. path: 'dashboard/team-inquiry',
  121. component: () => import('@/ui-refactor/views/team-inquiry/TeamInquiryPage.vue'),
  122. name: 'MemberTeamInquiry',
  123. meta: {
  124. title: 'Team Inquiry',
  125. publicLayout: {
  126. hero: {
  127. breadcrumbs: [
  128. { text: 'My Account', to: '/dashboard/index' },
  129. { text: 'Team Inquiry' }
  130. ],
  131. titleParts: [{ text: 'Your team, ' }, { text: 'at a glance.', accent: true }],
  132. subtitle:
  133. 'View your personal member summary and your direct team details. Calculations are refreshed at the end of each pay cycle.'
  134. }
  135. }
  136. }
  137. }
  138. ]
  139. },
  140. refactorRouter
  141. ]
  142. /**
  143. * asyncRoutes
  144. * the routes that need to be dynamically loaded based on user roles
  145. */
  146. export const asyncRoutes = [
  147. {
  148. path: '/permission',
  149. component: Layout,
  150. redirect: '/permission/page',
  151. alwaysShow: true, // will always show the root menu
  152. name: 'Permission',
  153. meta: {
  154. title: 'permission',
  155. icon: 'lock',
  156. roles: ['admin', 'editor'] // you can set roles in root nav
  157. },
  158. children: [
  159. {
  160. path: 'page',
  161. component: () => import('@/views/permission/page'),
  162. name: 'PagePermission',
  163. meta: {
  164. title: 'pagePermission',
  165. roles: ['admin'] // or you can only set roles in sub nav
  166. }
  167. },
  168. {
  169. path: 'directive',
  170. component: () => import('@/views/permission/directive'),
  171. name: 'DirectivePermission',
  172. meta: {
  173. title: 'directivePermission'
  174. // if do not set roles, means: this page does not require permission
  175. }
  176. },
  177. {
  178. path: 'role',
  179. component: () => import('@/views/permission/role'),
  180. name: 'RolePermission',
  181. meta: {
  182. title: 'rolePermission',
  183. roles: ['admin']
  184. }
  185. }
  186. ]
  187. },
  188. {
  189. path: '/icon',
  190. component: Layout,
  191. children: [
  192. {
  193. path: 'index',
  194. component: () => import('@/views/icons/index'),
  195. name: 'Icons',
  196. meta: { title: 'icons', icon: 'icon', noCache: true }
  197. }
  198. ]
  199. },
  200. componentsRouter,
  201. chartsRouter,
  202. nestedRouter,
  203. tableRouter,
  204. shopRouter,
  205. profileRouter,
  206. configRouter,
  207. atlasRouter,
  208. articleRouter,
  209. bonusRouter,
  210. financeRouter,
  211. userRouter,
  212. {
  213. path: '/error',
  214. component: Layout,
  215. redirect: 'noRedirect',
  216. name: 'ErrorPages',
  217. meta: {
  218. title: 'errorPages',
  219. icon: '404'
  220. },
  221. children: [
  222. {
  223. path: '401',
  224. component: () => import('@/views/error-page/401'),
  225. name: 'Page401',
  226. meta: { title: 'page401', noCache: true }
  227. },
  228. {
  229. path: '404',
  230. component: () => import('@/views/error-page/404'),
  231. name: 'Page404',
  232. meta: { title: 'page404', noCache: true }
  233. }
  234. ]
  235. },
  236. {
  237. path: '/error-log',
  238. component: Layout,
  239. children: [
  240. {
  241. path: 'log',
  242. component: () => import('@/views/error-log/index'),
  243. name: 'ErrorLog',
  244. meta: { title: 'errorLog', icon: 'bug' }
  245. }
  246. ]
  247. },
  248. // 404 page must be placed at the end !!!
  249. { path: '*', redirect: '/404', hidden: true }
  250. ]
  251. const createRouter = () =>
  252. new Router({
  253. // mode: 'history', // require service support
  254. scrollBehavior: () => ({ y: 0 }),
  255. routes: constantRoutes.concat(asyncRoutes)
  256. // routes: constantRoutes.concat(asyncRoutes)
  257. })
  258. const router = createRouter()
  259. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  260. export function resetRouter() {
  261. const newRouter = createRouter()
  262. router.matcher = newRouter.matcher // reset router
  263. }
  264. export function selfAddRoutes(params) {
  265. const newRouter = createRouter()
  266. router.matcher = newRouter.matcher
  267. router.addRoutes(params)
  268. }
  269. export default router