Skip to content

Commit a7a226f

Browse files
improve generator warning
1 parent 5501330 commit a7a226f

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

  • packages/router-generator

packages/router-generator/src/generator.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,22 @@ ${acc.routeTree.map((child) => `${child.variableName}Route: typeof ${getResolved
10901090
})
10911091

10921092
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)
10961109
return null
10971110
}
10981111
if (transformResult.result === 'error') {

packages/router-generator/tests/generator/virtual-physical-empty-path-conflict-root/routes/merged/route.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ import { createFileRoute } from '@tanstack/react-router'
22

33
// This route.tsx in a physical directory mounted at root level
44
// conflicts with the virtual root __root.tsx - can't have two root routes
5-
export const Route = createFileRoute('')({
6-
})
5+
export const Route = createFileRoute('')({})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
import { createRootRoute } from '@tanstack/react-router'
2+
13
export const Route = createRootRoute()

0 commit comments

Comments
 (0)