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
routeFilePrefixto 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:
routeFileIgnorePrefixwhich accepts a plain string androuteFileIgnorePatternwhich accepts a regex string and thus much more powerful.It'd be helpful to have a pattern option equivalent to
routeFilePrefixas well. It'll make the most sense to name itrouteFilePrefixPattern- and it'd also take a regex string to be as similar to existingrouteFileIgnorePatternas possible.Additional context - possible use case
In our project we have the convention that
index.tsxare 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.tsxis used to define roues.In theory we can just set set
routeFilePrefixtoindex.tsx- but it won't work. That's because there's the special file__root.tsxthat must not be ignored by the generator. DefiningrouteFilePrefixtoindex.tsxwould essentially make anything butindex.tsxignored. That's why we came up with the idea of having an option likerouteFilePrefixPattern.Alternative solution 1
Perhaps
routeFilePrefixcould also accept an array of strings (string[]) to allow matching multiple file prefixes.So, we wouldn't need need
routeFilePrefixPatternandrouteFilePrefix: ["index.tsx", "__root.tsx"]would be sufficientAlternative solution 2
Because
__root.tsxis 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