fix(dashboard): Allow empty subpaths for route extensions (#12030)
This commit is contained in:
1 parent
da52501518
commit
6d8390a529
2 files changed
+34
-10
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(dashboard): Allow empty subpaths for extension routes
|
||||||
@@ -126,7 +126,8 @@ const addRoute = (
|
|||||||
loader?: LoaderFunction,
|
loader?: LoaderFunction,
|
||||||
handle?: object,
|
handle?: object,
|
||||||
parallelRoutes?: RouteExtension[],
|
parallelRoutes?: RouteExtension[],
|
||||||
fullPath?: string
|
fullPath?: string,
|
||||||
|
componentPath?: string
|
||||||
) => {
|
) => {
|
||||||
if (!pathSegments.length) {
|
if (!pathSegments.length) {
|
||||||
return
|
return
|
||||||
@@ -137,21 +138,19 @@ const addRoute = (
|
|||||||
|
|
||||||
if (!route) {
|
if (!route) {
|
||||||
route = createBranchRoute(currentSegment)
|
route = createBranchRoute(currentSegment)
|
||||||
|
currentLevel.push(route)
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentFullPath = fullPath
|
const currentFullPath = fullPath
|
||||||
? `${fullPath}/${currentSegment}`
|
? `${fullPath}/${currentSegment}`
|
||||||
: currentSegment
|
: currentSegment
|
||||||
|
|
||||||
if (remainingSegments.length === 0) {
|
const isComponentSegment = currentFullPath === componentPath
|
||||||
|
|
||||||
|
if (isComponentSegment || remainingSegments.length === 0) {
|
||||||
route.children ||= []
|
route.children ||= []
|
||||||
const leaf = createLeafRoute(Component, loader)
|
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) {
|
if (handle) {
|
||||||
route.handle = handle
|
route.handle = handle
|
||||||
}
|
}
|
||||||
@@ -163,7 +162,17 @@ const addRoute = (
|
|||||||
leaf.children = processParallelRoutes(parallelRoutes, currentFullPath)
|
leaf.children = processParallelRoutes(parallelRoutes, currentFullPath)
|
||||||
route.children.push(leaf)
|
route.children.push(leaf)
|
||||||
|
|
||||||
currentLevel.push(route)
|
if (remainingSegments.length > 0) {
|
||||||
|
addRoute(
|
||||||
|
remainingSegments,
|
||||||
|
Component,
|
||||||
|
route.children,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
currentFullPath
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
route.children ||= []
|
route.children ||= []
|
||||||
addRoute(
|
addRoute(
|
||||||
@@ -173,7 +182,8 @@ const addRoute = (
|
|||||||
loader,
|
loader,
|
||||||
handle,
|
handle,
|
||||||
parallelRoutes,
|
parallelRoutes,
|
||||||
currentFullPath
|
currentFullPath,
|
||||||
|
componentPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,7 +205,16 @@ export const createRouteMap = (
|
|||||||
? path.replace(ignore, "").replace(/^\/+/, "")
|
? path.replace(ignore, "").replace(/^\/+/, "")
|
||||||
: path.replace(/^\/+/, "")
|
: path.replace(/^\/+/, "")
|
||||||
const pathSegments = cleanedPath.split("/").filter(Boolean)
|
const pathSegments = cleanedPath.split("/").filter(Boolean)
|
||||||
addRoute(pathSegments, Component, root, loader, handle, children)
|
addRoute(
|
||||||
|
pathSegments,
|
||||||
|
Component,
|
||||||
|
root,
|
||||||
|
loader,
|
||||||
|
handle,
|
||||||
|
children,
|
||||||
|
undefined,
|
||||||
|
path
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|||||||
Reference in new issue
Block a user