Jelajahi Sumber

fix[backend-cli]: 路由

chenlei 1 tahun lalu
induk
melakukan
591401d558

+ 1 - 1
packages/backend-cli/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@dage/backend-cli",
-  "version": "1.2.3",
+  "version": "1.2.4",
   "description": "创建后台模板",
   "main": "index.js",
   "files": [

+ 3 - 1
packages/backend-cli/template/src/pages/Layout/components/Header/index.tsx

@@ -38,10 +38,12 @@ const generateBreadcrumb = (
       breadcrumb.push({
         title: item.title,
         href:
-          i < paths.length - 1
+          i < paths.length - 1 && item.children
             ? `${isHashRoute ? "#" : ""}${item.redirect || item.path}`
             : undefined,
       });
+
+      if (!item.children) break;
     }
   }
 

+ 9 - 2
packages/backend-cli/template/src/pages/Layout/utils.ts

@@ -22,11 +22,18 @@ export const findRouteByPath = (
   routes: DageRouteItem[],
   path: string
 ): DageRouteItem | null => {
+  const temp = path.split("/");
+
   for (const route of routes) {
-    if (route.path === path) {
+    if (route.path.replace(/\/:[^/]+/g, "") === path) {
       return route;
     }
-    if (route.children) {
+    if (
+      // 首层没必要向下遍历
+      temp.length !== 2 &&
+      route.path.indexOf(temp[1]) > -1 &&
+      route.children
+    ) {
       const subRoute = findRouteByPath(route.children, path);
       if (subRoute) {
         return subRoute;