Next.js 10 localization in pathname
See original GitHub issueThe new built-in localization in Next.js 10 allows to have the locale as a path prefix, e.g.:
/about
/de/about
/es/about
All three routes will open pages/about.tsx
. This works fine when I run it locally.
When I deploy it using serverless-next.js, it gives a 404 for /de/about
and /es/about
. Just /about
still works.
Is this something that the Serverless Next.js Component doesn’t support yet, or am I doing something wrong? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:32
- Comments:56 (5 by maintainers)
Top Results From Across the Web
Advanced Features: Internationalized Routing - Next.js
Next.js has built-in support for internationalized (i18n) routing since v10.0.0 . You can provide a list of locales, the default locale, and domain-specific ......
Read more >How can I localize routes with the nextJs and next-i18next like ...
I'm using NextJs 10.0.5 with next-i18next 8.1.0 to localize my application. As we all know nextJs 10 has subpath routing for ...
Read more >Advanced internationalization with Next.js and middleware
Next.js 12 introduced middleware for handling logic at the CDN level ... it for is advanced internationalization and content localization.
Read more >The complete guide to internationalization in Next.js
Learn how to make your Next.js app international with smooth translation features in this advanced, step-by-step tutorial.
Read more >Internalization with NextJS | Amourycodes
Building a multilingual website or an application has 2 parts to it - 1. Internationalization(i18n), and 2. Localization (l10n). Next.js provides a way...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi all, after days of headaches I’ve managed to find a workaround which seems to work for me. Here’s some notable configs that managed to work for me, no guarantees for anyone else I suppose.
Removed
target: 'serverless'
fromnext.config.js
. Also added i18n configs manually.Changed the next-i18next.config file from a .js to a .ts Updated the contents of the
next-i18next.config.ts
file to a duplication of what is defined in thenext.config.js
i18n field.In tsconfig.json (root of the project) I included the newly created
next-i18next.config.ts
file.In
_app.tsx
, when wrapping the application with theappWithTranslation
function, I imported the variable from previously madenext-i18next.config.ts
config, and passed it as a second parameter to the appWithTranslation function call.And did so similarly with any page that needs
getStaticProps
, example page below:What an absolute pain that was. I hope this helps anyone out there with the same issue. Also hope this gets resolved and that serverless next.js can properly locate the module without needing to duplicate the configs.
Just some musings: It seems when you run
serverless
it duplicates thenext-i18next.config.js
file and creates another file likenext-i18next.config.original<hash>.js
not sure if that’s the issue or not…Can provide more details of my projects configs if necessary. Good luck all.
Have published
@sls-next/serverless-component@1.19.0-alpha.29
which should have locale subpath routing working. Note that you do need to addAccept-Language
header for the root-level locale redirect (it’s added by default in default behavior, but if you override it, you will have to add it yourself).I haven’t extensively tested it nor added complete tests for it yet, so please treat it as a preview for now and report any issues by opening a bug report. Thanks!
Note: domain-based routing will be a separate issue