Skip to content

fix(router-generator): Pathless Layout Route Renders Empty HTML #4003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
31 changes: 30 additions & 1 deletion packages/router-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,21 @@ export async function generator(config: Config, root: string) {
routeTree.push(node)
}

if (node.children && node.children.length > 0) {
node.isNonPath = updateIsNonPath(node)
}

if (node.parent) {
node.parent.isNonPath = updateIsNonPath(node.parent)
}

routeNodes.push(node)
}

for (const node of onlyGeneratorRouteNodes) {
await handleNode(node)
}

checkRouteFullPathUniqueness(
preRouteNodes.filter(
(d) =>
Expand Down Expand Up @@ -835,7 +844,12 @@ function removeGroups(s: string) {
*/
function determineNodePath(node: RouteNode) {
return (node.path = node.parent
? node.routePath?.replace(node.parent.routePath ?? '', '') || '/'
? node.routePath?.replace(
node.parent._fsRouteType === 'pathless_layout'
? (node.parent.path ?? '')
: (node.parent.routePath ?? ''),
'',
) || '/'
: node.routePath)
}

Expand Down Expand Up @@ -1094,3 +1108,18 @@ export function startAPIRouteSegmentsFromTSRFilePath(

return segments
}

/**
* Only true if all children are pathless_layout or
* if children are of different types but all their children are pathless_layout
* @param node
* @returns
*/
export const updateIsNonPath = (node: RouteNode) => {
if (node._fsRouteType === 'pathless_layout') return true
return node.children?.every(
(child) =>
child._fsRouteType === 'pathless_layout' ||
(child.children?.length && child.isNonPath),
)
}
Loading