Add routeFilePrefixPattern
to the API of file based routing
#4841
ExcellentAmericanEagle
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, the API of file based routing provides the option
routeFilePrefix
to specify the prefix all files must have to be considered for routing.The opposite - ignoring certain file paths from being treated as routing files features two options:
routeFileIgnorePrefix
which accepts a plain string androuteFileIgnorePattern
which accepts a regex string and thus much more powerful.It'd be helpful to have a pattern option equivalent to
routeFilePrefix
as well. It'll make the most sense to name itrouteFilePrefixPattern
- and it'd also take a regex string to be as similar to existingrouteFileIgnorePattern
as possible.Additional context - possible use case
In our project we have the convention that
index.tsx
are the only way to define routes in the project. All other file names shouldn't be treated as routes. My team finds it much more cleaner and familiar to Next.js's App Router whereaspage.tsx
is used to define roues.In theory we can just set set
routeFilePrefix
toindex.tsx
- but it won't work. That's because there's the special file__root.tsx
that must not be ignored by the generator. DefiningrouteFilePrefix
toindex.tsx
would essentially make anything butindex.tsx
ignored. That's why we came up with the idea of having an option likerouteFilePrefixPattern
.Alternative solution 1
Perhaps
routeFilePrefix
could also accept an array of strings (string[]
) to allow matching multiple file prefixes.So, we wouldn't need need
routeFilePrefixPattern
androuteFilePrefix: ["index.tsx", "__root.tsx"]
would be sufficientAlternative solution 2
Because
__root.tsx
is a mandatory file, why would one want to make the generator ignore this file? This name is hardcoded and not changeable.Beta Was this translation helpful? Give feedback.
All reactions