Newer
Older
DH_Apicture / src / router / index copy.js
@zhangqy zhangqy on 29 Nov 5 KB first commit
  1. import {
  2. createWebHistory,
  3. createWebHashHistory,
  4. createRouter,
  5. } from "vue-router";
  6. /* Layout */
  7. import Layout from "@/layout";
  8.  
  9. /**
  10. * Note: 路由配置项
  11. *
  12. * hidden: true // 当设置 true 的时候该路由不会再侧边栏出现 如401,login等页面,或者如一些编辑页面/edit/1
  13. * alwaysShow: true // 当你一个路由下面的 children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
  14. * // 只有一个时,会将那个子路由当做根路由显示在侧边栏--如引导页面
  15. * // 若你想不管路由下面的 children 声明的个数都显示你的根路由
  16. * // 你可以设置 alwaysShow: true,这样它就会忽略之前定义的规则,一直显示根路由
  17. * redirect: noRedirect // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
  18. * name:'router-name' // 设定路由的名字,一定要填写不然使用<keep-alive>时会出现各种问题
  19. * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
  20. * roles: ['admin', 'common'] // 访问路由的角色权限
  21. * permissions: ['a:a:a', 'b:b:b'] // 访问路由的菜单权限
  22. * meta : {
  23. noCache: true // 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
  24. title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
  25. icon: 'svg-name' // 设置该路由的图标,对应路径src/assets/icons/svg
  26. breadcrumb: false // 如果设置为false,则不会在breadcrumb面包屑中显示
  27. activeMenu: '/system/user' // 当路由设置了该属性,则会高亮相对应的侧边栏。
  28. }
  29. */
  30.  
  31. // 公共路由
  32. export const constantRoutes = [
  33. {
  34. path: "/redirect",
  35. component: Layout,
  36. hidden: true,
  37. children: [
  38. {
  39. path: "/redirect/:path(.*)",
  40. component: () => import("@/views/redirect/index.vue"),
  41. },
  42. ],
  43. },
  44.  
  45. {
  46. path: "/login",
  47. component: () => import("@/views/login"),
  48. hidden: true,
  49. },
  50. {
  51. path: "/register",
  52. component: () => import("@/views/register"),
  53. hidden: true,
  54. },
  55. {
  56. path: "/:pathMatch(.*)*",
  57. component: () => import("@/views/error/404"),
  58. hidden: true,
  59. },
  60. {
  61. path: "/401",
  62. component: () => import("@/views/error/401"),
  63. hidden: true,
  64. },
  65. {
  66. path: "",
  67. component: Layout,
  68. redirect: "/index",
  69. children: [
  70. {
  71. path: "/index",
  72. component: () => import("@/views/index"),
  73. name: "index",
  74. meta: {
  75. title: "首页",
  76. icon: "dashboard",
  77. affix: true,
  78. noCache: true,
  79. },
  80. },
  81. ],
  82. },
  83. {
  84. path: "/user",
  85. component: Layout,
  86. hidden: true,
  87. redirect: "noredirect",
  88. children: [
  89. {
  90. path: "profile",
  91. component: () => import("@/views/system/user/profile/index"),
  92. name: "Profile",
  93. meta: { title: "个人中心", icon: "user" },
  94. },
  95. ],
  96. },
  97. ];
  98.  
  99. // 动态路由,基于用户权限动态去加载
  100. export const dynamicRoutes = [
  101. {
  102. path: "/system/user-auth",
  103. component: Layout,
  104. hidden: true,
  105. permissions: ["system:user:edit"],
  106. children: [
  107. {
  108. path: "role/:userId(\\d+)",
  109. component: () => import("@/views/system/user/authRole"),
  110. name: "AuthRole",
  111. meta: { title: "分配角色", activeMenu: "/system/user" },
  112. },
  113. ],
  114. },
  115. {
  116. path: "/system/role-auth",
  117. component: Layout,
  118. hidden: true,
  119. permissions: ["system:role:edit"],
  120. children: [
  121. {
  122. path: "user/:roleId(\\d+)",
  123. component: () => import("@/views/system/role/authUser"),
  124. name: "AuthUser",
  125. meta: { title: "分配用户", activeMenu: "/system/role" },
  126. },
  127. ],
  128. },
  129. {
  130. path: "/system/dict-data",
  131. component: Layout,
  132. hidden: true,
  133. permissions: ["system:dict:list"],
  134. children: [
  135. {
  136. path: "index/:dictId(\\d+)",
  137. component: () => import("@/views/system/dict/data"),
  138. name: "Data",
  139. meta: { title: "字典数据", activeMenu: "/system/dict" },
  140. },
  141. ],
  142. },
  143. {
  144. path: "/monitor/job-log",
  145. component: Layout,
  146. hidden: true,
  147. permissions: ["monitor:job:list"],
  148. children: [
  149. {
  150. path: "index/:jobId(\\d+)",
  151. component: () => import("@/views/monitor/job/log"),
  152. name: "JobLog",
  153. meta: { title: "调度日志", activeMenu: "/monitor/job" },
  154. },
  155. ],
  156. },
  157. {
  158. path: "/tool/gen-edit",
  159. component: Layout,
  160. hidden: true,
  161. permissions: ["tool:gen:edit"],
  162. children: [
  163. {
  164. path: "index/:tableId(\\d+)",
  165. component: () => import("@/views/tool/gen/editTable"),
  166. name: "GenEdit",
  167. meta: { title: "修改生成配置", activeMenu: "/tool/gen" },
  168. },
  169. ],
  170. },
  171. ];
  172.  
  173. const router = createRouter({
  174. // history: createWebHistory(),
  175. history: createWebHashHistory(),
  176. routes: constantRoutes,
  177. scrollBehavior(to, from, savedPosition) {
  178. if (savedPosition) {
  179. return savedPosition;
  180. } else {
  181. return { top: 0 };
  182. }
  183. },
  184. });
  185.  
  186. export default router;