I am attempting to implement localized routes with an optional first parameter in the form of /lang?/../../
, all without requiring a custom server. Starting from NextJS version 9.5, there is a new dynamic optional parameters feature that can be set up by creating a folder or file named: [[...param]]
. I have implemented this.
The issue I am facing is that I have other existing routes and I want all of them to include the language prefix as optional, defaulting to a specified language if none is provided.
I have created a folder called [[...lang]]
with an index.js file containing a simple function component for testing purposes. The optional parameter now works for the homepage /
and /en
. However, I also have other files like about.js
which I want to be accessible with the optional language prefix, such as /en/about
and /about
.
I encountered an error when attempting to place about.js
inside [[...lang]]
:
Failed to reload dynamic routes: Error: Catch-all must be the last part of the URL.
Although I understand the reason behind this error, I have a predefined list of languages ['en', 'fr'], thus I could easily check for the presence of a language parameter.
Is there a method, without resorting to a custom server, to make use of an optionally dynamic initial path segment, such as
/en/about
and /about
?