react-router icon indicating copy to clipboard operation
react-router copied to clipboard

ignoredRouteFiles configuration in flatRoutes not working - ignored route files are still accessible

Open wangpf1129 opened this issue 4 months ago • 3 comments

Reproduction

demo link

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"

wangpf1129 avatar Aug 12 '25 08:08 wangpf1129

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

Image

rururux avatar Aug 18 '25 03:08 rururux

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. 🤔

rururux avatar Aug 19 '25 10:08 rururux

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

rururux avatar Aug 26 '25 15:08 rururux