Hi everyone!
I’m working on a multilingual website using Next.js (with the app
directory) and Prismic, and I’ve run into an issue with my root resolver when trying to hide the master language (fr
) in the URL.
Here’s my setup and the issue I’m facing:
Route Configuration (Root Resolver)
I’ve defined my Prismic routes as follows:
const routes: prismic.ClientConfig["routes"] = [
{
type: "home-page",
path: "/:lang?/", // `lang` is optional
},
{
type: "page",
path: "/:lang?/:uid",
},
];
Locale Definition in next.config.ts
Here’s how I fetch and define the locales dynamically:
const nextConfig = async (): Promise<NextConfig> => {
const client = createClient();
const repository = await client.getRepository();
const locales = repository.languages.map((lang) => lang.id);
console.log("locales", locales); // Logs available locales
return {
output: "export",
reactStrictMode: true,
i18n: {
locales: ["en", "fr"], // Supported locales
defaultLocale: "fr", // Master language
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**.prismic.io",
},
],
},
redirects: async () => {
return [];
},
};
};
Folder Structure (app
Directory)
I’ve structured my app
folder as follows to handle both root and language-specific routes:
app/
├── [lang]/
│ ├── [...uids]/page.tsx // For language-specific pages
│ ├── page.tsx // For language-specific homepages
├── [...uids]/page.tsx // For master language pages
├── page.tsx // For master language homepage
Current Behavior
Here’s what works and what doesn’t:
/
→ Shows thefr
(default/master language) homepage./fr
→ Shows thefr
homepage./en
→ Shows the English homepage./fr/bonjour
→ Works as expected./en/bonjour
→ Works as expected./bonjour
→ Fails with the following error:
[Server] Error: Some(bonjour) is not a valid language code
It seems like the root resolver doesn’t recognize bonjour
as a valid page for the master language and instead tries to interpret it as a language code.
What I Need
I want to:
- Hide the default language (
fr
) in the URL for the master language, e.g.,/bonjour
instead of/fr/bonjour
. - Maintain full support for other languages, e.g.,
/en/bonjour
. - Ensure the site remains in SSG mode using app directory.
Question
What am I doing wrong with my current setup? Why is the root resolver not identifying bonjour
as a valid page in the master language? Is there a better way to handle this in the app
directory with the [...uids]
structure?
Any help or suggestions would be greatly appreciated!