Skip to content

Commit 709a7c8

Browse files
authored
fix: Fixing Nesting Issues with multiple layouts (#741)
When there are multiple nested layouts it is possible for the generator to not nest sub paths correctly.
1 parent b3c81b9 commit 709a7c8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

packages/router-cli/src/generator.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,27 @@ function replaceBackslash(s?: string) {
367367
return s?.replace(/\\/gi, '/')
368368
}
369369

370-
function hasParentRoute(routes: RouteNode[], routeToCheck: string | undefined): RouteNode | null {
370+
export function hasParentRoute(routes: RouteNode[], routeToCheck: string | undefined): RouteNode | null {
371371
if (!routeToCheck || routeToCheck === "/") {
372372
return null;
373373
}
374-
for (const route of routes) {
374+
375+
const sortedNodes = multiSortBy(routes, [
376+
(d) => d.routePath!.length * -1,
377+
(d) => d.variableName,
378+
379+
]).filter((d) => d.routePath !== `/${rootPathId}`)
380+
381+
for (const route of sortedNodes) {
375382
if (route.routePath === '/') continue;
383+
376384
if (routeToCheck.startsWith(`${route.routePath}/`) && route.routePath !== routeToCheck) {
377385
return route;
378386
}
379387
}
380388
const segments = routeToCheck.split("/");
381389
segments.pop(); // Remove the last segment
382390
const parentRoute = segments.join("/");
391+
383392
return hasParentRoute(routes, parentRoute);
384393
}

0 commit comments

Comments
 (0)