index.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-10-14 17:17:53
  4. * @LastEditTime: 2022-02-28 17:54:47
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \Foshan4A\src\router\index.js
  8. */
  9. import Vue from 'vue'
  10. import Router from 'vue-router'
  11. Vue.use(Router)
  12. /* Layout */
  13. import routesOne from './routes/routes-file-one'
  14. import routesFour from './routes/routes-file-four'
  15. import routesTwo from './routes/routes-file-two'
  16. import routesThree from './routes/routes-file-three'
  17. import routesFive from './routes/routes-file-five'
  18. /**
  19. * Note: sub-menu only appear when route children.length >= 1
  20. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  21. *
  22. * hidden: true if set true, item will not show in the sidebar(default is false)
  23. * alwaysShow: true if set true, will always show the root menu
  24. * if not set alwaysShow, when item has more than one children route,
  25. * it will becomes nested mode, otherwise not show the root menu
  26. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  27. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  28. * meta : {
  29. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  30. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  31. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  32. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  33. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  34. }
  35. */
  36. const routesPush = (arr, routes) => {
  37. if (!Array.isArray(arr)) return '请传入数组格式路由表'
  38. for (let i = 0; i < arr.length; i++) {
  39. routes.unshift(arr[i])
  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: '/login',
  50. component: () => import('@/views/login/index'),
  51. hidden: true
  52. },
  53. {
  54. path: '/404',
  55. component: () => import('@/views/404'),
  56. hidden: true
  57. },
  58. // 404 page must be placed at the end !!!
  59. // { path: '*', redirect: '/404', hidden: true }
  60. ]
  61. // 插入路由
  62. export const asyncRoutes = []
  63. routesPush([...routesOne, ...routesTwo, ...routesThree, ...routesFour, ...routesFive], asyncRoutes)
  64. asyncRoutes.push({ path: '/', component: () => import('@/views/noPower'), hidden: true })
  65. asyncRoutes.push({ path: '*', component: () => import('@/views/404'), hidden: true })
  66. const createRouter = () => new Router({
  67. // mode: 'history', // require service support
  68. scrollBehavior: () => ({ y: 0 }),
  69. routes: constantRoutes
  70. })
  71. const router = createRouter()
  72. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  73. export function resetRouter () {
  74. const newRouter = createRouter()
  75. router.matcher = newRouter.matcher // reset router
  76. }
  77. export default router