0

In NextJS's routing system, if I navigate to //mysite.com/about/ it serves my project file pages/about.js

But when using i18n to add mysite.com/fr/, it still serves pages/about.js, not pages/fr/about.js. This is fine in most cases because you want to serve the same file and just change the text by detecting the locale /fr/ with useRouter.

But in my case I want to serve a completely different file based on the sub-path /fr/ in the pathname.

In _app.js I have props of Component, pageProps and router, but it's too late to conditionally serve a different file at this point because Component has already been determined by NextJS. Even though the prop router.inFlightMode has detected the language change.

I'm hoping there is simply a routing config to change somewhere that will include the sub-path in the pathname used to point to a file.

  • it may be fallbackLng is something that could help: https://github.com/i18next/next-i18next#fallback-locales – adrai Oct 19 '22 at 09:23
  • 1
    You could look into using [`rewrites`](https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewrites-with-i18n-support) to map the `/fr` paths to different destinations. – juliomalves Oct 21 '22 at 21:38

0 Answers0