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