@tanstack/router-generator 1.145.1 → 1.145.4

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
@@ -1090,9 +1090,22 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1090
1090
  })
1091
1091
 
1092
1092
  if (transformResult.result === 'no-route-export') {
1093
- this.logger.warn(
1094
- `Route file "${node.fullPath}" does not contain any route piece. This is likely a mistake.`,
1095
- )
1093
+ const fileName = path.basename(node.fullPath)
1094
+ const dirName = path.dirname(node.fullPath)
1095
+ const ignorePrefix = this.config.routeFileIgnorePrefix
1096
+ const ignorePattern = this.config.routeFileIgnorePattern
1097
+ const suggestedFileName = `${ignorePrefix}${fileName}`
1098
+ const suggestedFullPath = path.join(dirName, suggestedFileName)
1099
+
1100
+ let message = `Warning: Route file "${node.fullPath}" does not export a Route. This file will not be included in the route tree.`
1101
+ message += `\n\nIf this file is not intended to be a route, you can exclude it using one of these options:`
1102
+ message += `\n 1. Rename the file to "${suggestedFullPath}" (prefix with "${ignorePrefix}")`
1103
+ message += `\n 2. Use 'routeFileIgnorePattern' in your config to match this file`
1104
+ message += `\n\nCurrent configuration:`
1105
+ message += `\n routeFileIgnorePrefix: "${ignorePrefix}"`
1106
+ message += `\n routeFileIgnorePattern: ${ignorePattern ? `"${ignorePattern}"` : 'undefined'}`
1107
+
1108
+ this.logger.warn(message)
1096
1109
  return null
1097
1110
  }
1098
1111
  if (transformResult.result === 'error') {
@@ -1357,7 +1370,24 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1357
1370
  prefixMap: RoutePrefixMap,
1358
1371
  config?: Config,
1359
1372
  ) {
1360
- const parentRoute = hasParentRoute(prefixMap, node, node.routePath)
1373
+ let parentRoute = hasParentRoute(prefixMap, node, node.routePath)
1374
+
1375
+ // Fallback: check acc.routeNodesByPath for parents not in prefixMap
1376
+ // This handles virtual routes created from lazy-only files that weren't
1377
+ // in the initial prefixMap build
1378
+ if (!parentRoute && node.routePath) {
1379
+ let searchPath = node.routePath
1380
+ while (searchPath.length > 0) {
1381
+ const lastSlash = searchPath.lastIndexOf('/')
1382
+ if (lastSlash <= 0) break
1383
+ searchPath = searchPath.substring(0, lastSlash)
1384
+ const candidate = acc.routeNodesByPath.get(searchPath)
1385
+ if (candidate && candidate.routePath !== node.routePath) {
1386
+ parentRoute = candidate
1387
+ break
1388
+ }
1389
+ }
1390
+ }
1361
1391
 
1362
1392
  if (parentRoute) node.parent = parentRoute
1363
1393
 
@@ -1489,7 +1519,11 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
1489
1519
  }
1490
1520
 
1491
1521
  acc.routeNodes.push(node)
1492
- if (node.routePath && !node.isVirtual) {
1522
+ if (node.routePath) {
1523
+ // Always register routes by path so child routes can find parents.
1524
+ // Virtual routes (created from lazy-only files) also need to be registered
1525
+ // so that index routes like path.index.lazy.tsx can find their parent path.lazy.tsx.
1526
+ // If a non-virtual route is later processed for the same path, it will overwrite.
1493
1527
  acc.routeNodesByPath.set(node.routePath, node)
1494
1528
  }
1495
1529
  }