index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import Vue from 'vue' // 引入vue
  2. import Router from 'vue-router' // 引入vue-router
  3. import Layout from '@/layout' // 页面布局 Layou
  4. Vue.use(Router)
  5. /**
  6. * 注意: 子菜单仅在route的children.length> = 1时出现
  7. * hidden: true 如果为true,将不会显示侧边栏sidebar(默认值 false)
  8. * redirect: noRedirect 如果设置为noRedirect,则不会重定向
  9. * name:'router-name' name被<keep-alive>使用 (必须设置!!!)
  10. * meta : {
  11. title: 'title' 侧边栏sidebar中显示的名称(推荐设置)
  12. icon: 'svg-name' 侧边栏sidebar中显示的icon图标
  13. }
  14. */
  15. /**
  16. * constantRoutes
  17. * 没有权限要求的页面,所有角色roles都可以访问
  18. */
  19. export const constantRoutes = [
  20. {
  21. path: '/',
  22. component: Layout,
  23. redirect: 'noRedirect',
  24. },
  25. {
  26. path: '/indexLayout/index',
  27. component: Layout,
  28. children:[{
  29. path: '/indexLayout/index',
  30. name: '/indexLayout/index',
  31. component: () => import('@/views/indexLayout/index'),
  32. meta: { title: '首页', icon: '' },
  33. hidden: true,
  34. }]
  35. },
  36. //CDA的路由
  37. {
  38. path: '/home',
  39. component: Layout,
  40. hidden: true,
  41. redirect: 'noRedirect',
  42. children: [{
  43. path: '/home',
  44. name: 'home',
  45. component: () => import('@/views/home/index'),
  46. meta: { title: 'CDA首页', icon: '' },
  47. children: [
  48. {
  49. path: '/home/myproject',
  50. component: () => import('@/views/home/myproject/index'),
  51. meta: { title: '我的项目', icon: '' },
  52. hidden: true
  53. },
  54. {
  55. path: '/home/openproject',
  56. component: () => import('@/views/home/openproject/index'),
  57. meta: { title: '公开项目', icon: '' },
  58. hidden: true
  59. },
  60. ]
  61. }]
  62. },
  63. {
  64. path: '/index',
  65. component: Layout,
  66. children:[{
  67. path: '/index',
  68. name: 'index',
  69. component: () => import('@/views/index/index'),
  70. meta: { title: '项目新建', icon: '' },
  71. hidden: true,
  72. }]
  73. },
  74. //HCFD
  75. // {
  76. // path: 'HCFDLab/index',
  77. // component: Layout,
  78. // children:[{
  79. // path: '/index',
  80. // name: 'index',
  81. // component: () => import('@/views/HCFDLab/index'),
  82. // meta: { title: '项目新建', icon: '' },
  83. // hidden: true,
  84. // }]
  85. // },
  86. // 登陆
  87. {
  88. path: '/login',
  89. component: Layout,
  90. hidden: true,
  91. redirect: 'noRedirect',
  92. children: [{
  93. path: 'index',
  94. name: 'Index',
  95. component: () => import('@/views/login/index'),
  96. meta: { title: '登录', icon: '' }
  97. }]
  98. },
  99. {
  100. path: '/forget',
  101. component: Layout,
  102. hidden: true,
  103. redirect: 'noRedirect',
  104. children: [{
  105. path: 'index',
  106. name: 'Index',
  107. component: () => import('@/views/forget/index'),
  108. meta: { title: '忘记密码', icon: '' }
  109. }]
  110. },
  111. {
  112. path: '/register',
  113. component: Layout,
  114. hidden: true,
  115. redirect: 'noRedirect',
  116. children: [{
  117. path: 'index',
  118. name: 'Index',
  119. component: () => import('@/views/register/index'),
  120. meta: { title: '免费注册', icon: '' }
  121. }]
  122. },
  123. {
  124. path: '/protocol',
  125. component: Layout,
  126. hidden: true,
  127. redirect: 'noRedirect',
  128. children: [{
  129. path: 'index',
  130. name: 'Index',
  131. component: () => import('@/views/protocol/index'),
  132. meta: { title: '注册协议', icon: '' }
  133. }]
  134. },
  135. {
  136. path: '/fail404',
  137. component: () => import('@/views/fail404/index'),
  138. hidden: true
  139. },
  140. // 404页必须放在末尾 !!!
  141. {
  142. path: '*',
  143. redirect: '/indexLayout/index',
  144. component: () => import('@/views/indexLayout/index'),
  145. hidden: true
  146. }
  147. ]
  148. // 创建路由(hashHistory是以#后面的路径进行处理,通过HTML5 History进行前端路由管理,而 browserHistory 则是类似我们通常的页面访问路径,并没有#,但要通过服务端的配置,能够访问指定的url 都定向到当前页面,从而能够进行前端的路由管理。)
  149. const createRouter = () => new Router({
  150. // mode: 'history', // history模式(browserHistory需要后端支持,本项目默认hashHistory )
  151. scrollBehavior: () => ({ y: 0 }),
  152. routes: constantRoutes
  153. })
  154. const router = createRouter()
  155. // 重置路由(通过将路由的matcher对象替换为新创建的路由实例中的matcher对象来实现)
  156. export function resetRouter() {
  157. const newRouter = createRouter()
  158. router.matcher = newRouter.matcher
  159. }
  160. export default router // 导出router