ignoredRouteFiles configuration in flatRoutes not working - ignored route files are still accessible
Reproduction
System Info
React Router Version: 7.x (latest)
@react-router/fs-routes": "^7.8.0
vite": "^6.3.3
Used Package Manager
npm
Expected Behavior
According to the official documentation:
Any modules in the app/routes directory will become routes in your application by default. The ignoredRouteFiles option allows you to specify files that should not be included as routes.
Actual Behavior
Files listed in ignoredRouteFiles are still:
- Rendering normally when accessed via their URL path
- Appearing to be processed by the routing system despite being "ignored"
I found the source of the problem.
The cause seems to be that the relative path from appDirectory, not the routes folder, is being passed to the regular expression validation.
https://github.com/remix-run/react-router/blob/75ab018b1ed0df2251a50d5073f0f4ae78d4e33e/packages/react-router-fs-routes/flatRoutes.ts#L299-L308
I'm planning on creating a PR to fix this soon, but I found a related issue. So, I'll start by making a draft PR. 🤔
For now, I'll write down the current solution here.
Key point: Write the relative path from the root folder for the folders and files you want to exclude. If you want to exclude a file, include the filename and extension. If you want to exclude a folder, include the folder name.
Examples:
/routes/ignore.tsx => routes/ignore.tsx
/routes/ignore/route.tsx => routes/ignore