Sfoglia il codice sorgente

feat: 更新路由初始化逻辑,返回第一个可访问路由

张涛 1 anno fa
parent
commit
b1e62be7f9
3 ha cambiato i file con 4 aggiunte e 5 eliminazioni
  1. 1 1
      dist/index.html
  2. 2 2
      src/router/index.js
  3. 1 2
      src/utils/permission.js

+ 1 - 1
dist/index.html

@@ -6,7 +6,7 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>大模型2.0</title>
     <script type="module" src="/config.js"></script>
-    <script type="module" crossorigin src="/assets/index-l2jDp5X1.js"></script>
+    <script type="module" crossorigin src="/assets/index-CRziEKqi.js"></script>
     <link rel="stylesheet" crossorigin href="/assets/index-ffnWl0r0.css">
   </head>
   <body>

+ 2 - 2
src/router/index.js

@@ -28,7 +28,7 @@ router.beforeEach(async (to, from, next) => {
   // 用户已授权的情况
   if (isAuthorized) {
     if (!hasRouteFlag) {
-      const { accessRoutes, accessFlatRoutes } = await initializeRoutes();
+      const { accessRoutes, accessFlatRoutes, firstAccessibleRoute } = await initializeRoutes();
       accessRoutes.forEach((route) => {
         if (route.path && route.component) {
           router.addRoute(route); // 动态添加可访问路由表
@@ -36,7 +36,7 @@ router.beforeEach(async (to, from, next) => {
       });
       flatRoutes = accessFlatRoutes;
       hasRouteFlag = true;
-      next({ ...to, replace: true });
+      next({ path: firstAccessibleRoute.path, replace: true });
     } else if (isLoginPage) {
       next('/');
     } else if (!flatRoutes.some((route) => route.path == to.path) && !isInWhiteList) {

+ 1 - 2
src/utils/permission.js

@@ -94,7 +94,6 @@ export const flattenRoutes = (routes) => {
   recurse(routes);
   return flatRoutes;
 };
-
 /**
  * 初始化路由,获取并格式化有权限的路由。
  *
@@ -114,7 +113,7 @@ export const initializeRoutes = () => {
   }
   accessRoutes = formatRoutes(routesList);
   accessFlatRoutes = flattenRoutes(accessRoutes);
-  return { accessRoutes, accessFlatRoutes };
+  return { accessRoutes, accessFlatRoutes, firstAccessibleRoute: accessFlatRoutes[0] };
 };
 
 /**