Skip to content

Commit

Permalink
fix: correctly generate route tree for nested layouts with path params (
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel authored Mar 10, 2024
1 parent 48d8424 commit 80ab1ec
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions packages/router-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,7 @@ export async function generator(config: Config) {
}

const cleanedPathIsEmpty = (node.cleanedPath || '').length === 0

node.isVirtualParentRequired = node.isLayout
? !cleanedPathIsEmpty && !node.parent
: false

node.isVirtualParentRequired = node.isLayout ? !cleanedPathIsEmpty : false
if (!node.isVirtual && node.isVirtualParentRequired) {
const parentRoutePath = removeLastSegmentFromPath(node.routePath) || '/'
const parentVariableName = routePathToVariable(parentRoutePath)
Expand Down Expand Up @@ -400,11 +396,8 @@ export async function generator(config: Config) {
await handleNode(node)
}

async function buildRouteConfig(
nodes: RouteNode[],
depth = 1,
): Promise<string> {
const children = nodes.map(async (node) => {
function buildRouteConfig(nodes: RouteNode[], depth = 1): string {
const children = nodes.map((node) => {
if (node.isRoot) {
return
}
Expand All @@ -416,17 +409,17 @@ export async function generator(config: Config) {
const route = `${node.variableName}Route`

if (node.children?.length) {
const childConfigs = await buildRouteConfig(node.children, depth + 1)
const childConfigs = buildRouteConfig(node.children, depth + 1)
return `${route}.addChildren([${spaces(depth * 4)}${childConfigs}])`
}

return route
})

return (await Promise.all(children)).filter(Boolean).join(`,`)
return children.filter(Boolean).join(`,`)
}

const routeConfigChildrenText = await buildRouteConfig(routeTree)
const routeConfigChildrenText = buildRouteConfig(routeTree)

const sortedRouteNodes = multiSortBy(routeNodes, [
(d) => (d.routePath?.includes(`/${rootPathId}`) ? -1 : 1),
Expand Down

0 comments on commit 80ab1ec

Please sign in to comment.