Skip to content

Commit 415b821

Browse files
committed
fix(router-generator): refactor isNonPath condition and determineNodePath
Signed-off-by: leesb971204 <[email protected]>
1 parent 2cbf653 commit 415b821

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

packages/router-generator/src/generator.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,12 @@ export async function generator(config: Config, root: string) {
402402
} else {
403403
routeTree.push(node)
404404
}
405-
406-
if (node.children && node.children.length > 0) {
407-
node.isNonPath = updateIsNonPath(node)
408-
}
409-
410-
if (node.parent) {
411-
node.parent.isNonPath = updateIsNonPath(node.parent)
405+
if (
406+
node._fsRouteType === 'layout' &&
407+
node.isVirtual &&
408+
node.isVirtualParentRoute
409+
) {
410+
node.isNonPath = node.children?.every((d) => d.isNonPath)
412411
}
413412

414413
routeNodes.push(node)
@@ -845,9 +844,7 @@ function removeGroups(s: string) {
845844
function determineNodePath(node: RouteNode) {
846845
return (node.path = node.parent
847846
? node.routePath?.replace(
848-
node.parent._fsRouteType === 'pathless_layout'
849-
? (node.parent.path ?? '')
850-
: (node.parent.routePath ?? ''),
847+
node.parent.isNonPath ? '' : (node.parent.routePath ?? ''),
851848
'',
852849
) || '/'
853850
: node.routePath)
@@ -1108,18 +1105,3 @@ export function startAPIRouteSegmentsFromTSRFilePath(
11081105

11091106
return segments
11101107
}
1111-
1112-
/**
1113-
* Only true if all children are pathless_layout or
1114-
* if children are of different types but all their children are pathless_layout
1115-
* @param node
1116-
* @returns
1117-
*/
1118-
export const updateIsNonPath = (node: RouteNode) => {
1119-
if (node._fsRouteType === 'pathless_layout') return true
1120-
return node.children?.every(
1121-
(child) =>
1122-
child._fsRouteType === 'pathless_layout' ||
1123-
(child.children?.length && child.isNonPath),
1124-
)
1125-
}

0 commit comments

Comments
 (0)