index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { getUserInfo } from "@lsq/base";
  2. import { createRouter, createWebHashHistory } from "vue-router";
  3. const router = createRouter({
  4. history: createWebHashHistory(import.meta.env.BASE_URL),
  5. routes: [
  6. {
  7. path: "/",
  8. name: "home",
  9. component: () => import("@/views/Home/index.vue"),
  10. meta: {
  11. hideTopNavBgColor: true,
  12. },
  13. },
  14. {
  15. path: "/home",
  16. name: "home2",
  17. component: () => import("@/views/Home2/index.vue"),
  18. meta: {
  19. showLogo: true,
  20. topNavBgColor: "rgba(248, 246, 242, 0.2)",
  21. },
  22. },
  23. {
  24. path: "/bookshelf",
  25. name: "bookshelf",
  26. component: () => import("@/views/Bookshelf/index.vue"),
  27. meta: {
  28. showLogo: true,
  29. needLogin: true,
  30. },
  31. },
  32. {
  33. path: "/stack",
  34. name: "stack",
  35. component: () => import("@/views/Stack/index.vue"),
  36. meta: {
  37. showLogo: true,
  38. },
  39. },
  40. {
  41. path: "/detail/:id/:type",
  42. name: "detail",
  43. component: () => import("@/views/Detail/index.vue"),
  44. meta: {},
  45. },
  46. ],
  47. });
  48. router.beforeEach((to, from, next) => {
  49. const userInfo = getUserInfo();
  50. if (to.name !== "detail") {
  51. // 除了 detail 页面,其他页面不需要暗黑模式
  52. localStorage.removeItem("vueuse-color-scheme");
  53. document.documentElement.className = "";
  54. }
  55. if (to.meta.needLogin && !userInfo) {
  56. next({
  57. name: "home",
  58. });
  59. return;
  60. }
  61. next();
  62. });
  63. export default router;