@tanstack/router-generator 1.144.0 → 1.145.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/generator.ts CHANGED
@@ -1357,7 +1357,24 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1357
1357
  prefixMap: RoutePrefixMap,
1358
1358
  config?: Config,
1359
1359
  ) {
1360
- const parentRoute = hasParentRoute(prefixMap, node, node.routePath)
1360
+ let parentRoute = hasParentRoute(prefixMap, node, node.routePath)
1361
+
1362
+ // Fallback: check acc.routeNodesByPath for parents not in prefixMap
1363
+ // This handles virtual routes created from lazy-only files that weren't
1364
+ // in the initial prefixMap build
1365
+ if (!parentRoute && node.routePath) {
1366
+ let searchPath = node.routePath
1367
+ while (searchPath.length > 0) {
1368
+ const lastSlash = searchPath.lastIndexOf('/')
1369
+ if (lastSlash <= 0) break
1370
+ searchPath = searchPath.substring(0, lastSlash)
1371
+ const candidate = acc.routeNodesByPath.get(searchPath)
1372
+ if (candidate && candidate.routePath !== node.routePath) {
1373
+ parentRoute = candidate
1374
+ break
1375
+ }
1376
+ }
1377
+ }
1361
1378
 
1362
1379
  if (parentRoute) node.parent = parentRoute
1363
1380
 
@@ -1489,7 +1506,11 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1489
1506
  }
1490
1507
 
1491
1508
  acc.routeNodes.push(node)
1492
- if (node.routePath && !node.isVirtual) {
1509
+ if (node.routePath) {
1510
+ // Always register routes by path so child routes can find parents.
1511
+ // Virtual routes (created from lazy-only files) also need to be registered
1512
+ // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.
1513
+ // If a non-virtual route is later processed for the same path, it will overwrite.
1493
1514
  acc.routeNodesByPath.set(node.routePath, node)
1494
1515
  }
1495
1516
  }