index.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {createRouter, createWebHashHistory, RouteRecordRaw} from "vue-router";
  2. export const Layout = () => import("@/layout/school.vue");
  3. // 静态路由
  4. export const constantRoutes: RouteRecordRaw[] = [
  5. {
  6. path: "/:pathMatch(.*)*", // 解决路由爆[Vue Router warn]: No match found for location with path
  7. meta: {title: "找不到此页面", hidden: true},
  8. component: () => import("@/views/error/404.vue"),
  9. },
  10. {
  11. path: "/redirect",
  12. component: Layout,
  13. meta: {hidden: true},
  14. children: [
  15. {
  16. path: "/redirect/:path(.*)",
  17. component: () => import("@/views/login/redirect.vue"),
  18. },
  19. ],
  20. },
  21. {
  22. path: "/login",
  23. component: () => import("@/views/login/index.vue"),
  24. meta: {title: "登录", hidden: true},
  25. },
  26. ];
  27. /**
  28. * 创建路由
  29. */
  30. const router = createRouter({
  31. history: createWebHashHistory(),
  32. routes: constantRoutes as RouteRecordRaw[],
  33. // 刷新时,滚动条位置还原
  34. scrollBehavior: () => ({left: 0, top: 0}),
  35. });
  36. /**
  37. * 重置路由
  38. */
  39. export function resetRouter() {
  40. router.replace({path: "/login"});
  41. }
  42. export default router;