Skip to content

Commit

Permalink
fix(router-generator): do not allow "_" as a routeFileIgnorePrefix (#…
Browse files Browse the repository at this point in the history
…2339)

* fix(router-generator): do not allow "_" as a `routeFIleIgnorePrefix`

* fix(router-generator): prompt the user if the rootRoute is undefined
  • Loading branch information
SeanCassiere authored Sep 15, 2024
1 parent 02f4e9a commit 7783678
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/router-generator/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,15 @@ ERROR: The "experimental.enableCodeSplitting" flag has been made stable and is n
`The "indexToken" and "routeToken" options must be different.`,
)
}

if (
config.routeFileIgnorePrefix &&
config.routeFileIgnorePrefix.trim() === '_'
) {
throw new Error(
`The "routeFileIgnorePrefix" cannot be an underscore ("_"). This is a reserved character used to denote a pathless route. Please use a different prefix.`,
)
}

return config
}
7 changes: 6 additions & 1 deletion packages/router-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ export async function generator(config: Config) {

const { rootRouteNode, routeNodes: beforeRouteNodes } = getRouteNodesResult
if (rootRouteNode === undefined) {
throw new Error(`rootRouteNode must not be undefined`)
let errorMessage = `rootRouteNode must not be undefined. Make sure you've added your root route into the route-tree.`
if (!config.virtualRouteConfig) {
errorMessage += `\nMake sure that you add a "${rootPathId}.${config.disableTypes ? 'js' : 'tsx'}" file to your routes directory.\nAdd the file in: "${config.routesDirectory}/${rootPathId}.${config.disableTypes ? 'js' : 'tsx'}"`
}
throw new Error(errorMessage)
}

const preRouteNodes = multiSortBy(beforeRouteNodes, [
(d) => (d.routePath === '/' ? -1 : 1),
(d) => d.routePath?.split('/').length,
Expand Down

0 comments on commit 7783678

Please sign in to comment.