Skip to content

Commit 9c13b5a

Browse files
committed
Refactor route path processing in appRouter
Updated the route path generation to apply dynamic segment replacement and trimming to each path segment individually, improving accuracy and maintainability.
1 parent 4ed6773 commit 9c13b5a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/package/components/appRouter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ const recursiveRoutes = (
9494
};
9595

9696
const allRoutes = Object.entries(routes).reduce(
97-
(acc: RouteObject[], [link, Component]) => {
98-
const routePath = link
97+
(acc: RouteObject[], [fullLink, Component]) => {
98+
const routePath = fullLink
9999
.replace(basePath.replace("app", ""), "")
100100
.replace(/^\//, "")
101101
.replace(/\.(js|jsx|ts|tsx)$/, "")
102102
.replace(/\/page$/, "")
103103
.replace(/\/index$/, "")
104-
.replace(/\[(.*)\]/, ":$1")
105104
.trim()
106105
.split("/")
106+
.map((link) => link.replace(/\[(.*)\]/, ":$1").trim())
107107
.filter(Boolean);
108108

109109
recursiveRoutes(routePath, acc, Component);

0 commit comments

Comments
 (0)