Next.js Discord

Discord Forum

You cannot use both an required and optional catch-all route

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
I think I have entered an edge case regarding my routing setup in Next.js. I use a headless CMS, hence why I have a [[...params]] catch all route in the root of my app directory. Aside from that, I also want to display a Quick View of a product in a parallel/intercepted route. In said quick-view (@modal/(.)products/[id]), I want to link to all products, for more information /products, but when linking to this page, the modal with quick view remains visible on the screen. In order for me to close the modal on navigation, the Next.js documentation advices me to create a [...catchall] route in the @modal directory with a page that returns null. But that's when I get following error:

Failed to reload dynamic routes: Error: You cannot use both an required and optional catch-all route at the same level ("[...catchall]" and "[[...params]]" ).

What is the best solution to this?

4 Replies

Transvaal lionOP
Here is a quick reproduction of the issue: https://github.com/imCorfitz/next-modal-issue-example
Transvaal lionOP
Transvaal lionOP
Hmm... tried to add the catchall route inside the photos subdirectory as well.. doesn't seem to work... 🤔 It is a weird oversight by Next.js I feel.
Transvaal lionOP
I have spent some time reading through the next.js source code - and the fact that they check for this kind of stuff makes me think it comes as no surprise this could be a conflict. Am I missing something obvious here?