From 6d8390a529e784aaae886006af0b5d364c2d2aba Mon Sep 17 00:00:00 2001 From: Kasper Fabricius Kristensen <45367945+kasperkristensen@users.noreply.github.com> Date: Fri, 28 Mar 2025 14:42:51 +0100 Subject: [PATCH] fix(dashboard): Allow empty subpaths for route extensions (#12030) --- .changeset/small-bananas-occur.md | 5 +++ .../src/dashboard-app/routes/utils.ts | 39 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 .changeset/small-bananas-occur.md diff --git a/.changeset/small-bananas-occur.md b/.changeset/small-bananas-occur.md new file mode 100644 index 0000000000..88fa4b0665 --- /dev/null +++ b/.changeset/small-bananas-occur.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard): Allow empty subpaths for extension routes diff --git a/packages/admin/dashboard/src/dashboard-app/routes/utils.ts b/packages/admin/dashboard/src/dashboard-app/routes/utils.ts index d03f598a46..9f3cd47bea 100644 --- a/packages/admin/dashboard/src/dashboard-app/routes/utils.ts +++ b/packages/admin/dashboard/src/dashboard-app/routes/utils.ts @@ -126,7 +126,8 @@ const addRoute = ( loader?: LoaderFunction, handle?: object, parallelRoutes?: RouteExtension[], - fullPath?: string + fullPath?: string, + componentPath?: string ) => { if (!pathSegments.length) { return @@ -137,21 +138,19 @@ const addRoute = ( if (!route) { route = createBranchRoute(currentSegment) + currentLevel.push(route) } const currentFullPath = fullPath ? `${fullPath}/${currentSegment}` : currentSegment - if (remainingSegments.length === 0) { + const isComponentSegment = currentFullPath === componentPath + + if (isComponentSegment || remainingSegments.length === 0) { route.children ||= [] const leaf = createLeafRoute(Component, loader) - /** - * The handle needs to be set on the wrapper route object, - * in order for it to be resolved correctly thoughout - * the branch. - */ if (handle) { route.handle = handle } @@ -163,7 +162,17 @@ const addRoute = ( leaf.children = processParallelRoutes(parallelRoutes, currentFullPath) route.children.push(leaf) - currentLevel.push(route) + if (remainingSegments.length > 0) { + addRoute( + remainingSegments, + Component, + route.children, + undefined, + undefined, + undefined, + currentFullPath + ) + } } else { route.children ||= [] addRoute( @@ -173,7 +182,8 @@ const addRoute = ( loader, handle, parallelRoutes, - currentFullPath + currentFullPath, + componentPath ) } } @@ -195,7 +205,16 @@ export const createRouteMap = ( ? path.replace(ignore, "").replace(/^\/+/, "") : path.replace(/^\/+/, "") const pathSegments = cleanedPath.split("/").filter(Boolean) - addRoute(pathSegments, Component, root, loader, handle, children) + addRoute( + pathSegments, + Component, + root, + loader, + handle, + children, + undefined, + path + ) }) return root