Replies: 1 comment 2 replies
-
Yep, that's indeed a bit of a tricky one! The
Not sure if redirecting to the home page on locale change is an option for you, but it's certainly the simplest implementation for this case. Alternatively, you could consider intercepting requests for pathnames like |
Beta Was this translation helpful? Give feedback.
-
Handling Locale-Specific Dynamic Slugs in Nested Routes with Strapi and Next.js
I am working on a multilingual application using Next.js (App Router) and Strapi.
My routes are structured as follows:
[locale]/complexes/[slug]
Each language in Strapi has its own unique slug. For example:
English:
/en/complexes/some-slug
Spanish:
/es/complexes/some-slug-es
When I switch locales, the route doesn't update to the correct slug for the new language. Instead, it reuses the current slugs, resulting in an invalid URL like:
/es/complexes/some-slug
Setup Details
Current Implementation:
I'm using generateStaticParams to pre-generate all possible locale-specific paths.
The primary issue is that the locale switch fails to accurately map the slug to the translated values in the target language. This leads to:
Incorrect URLs for the target locale.
User confusion and potential 404 errors.
How can I ensure that generateStaticParams correctly maps all locale-specific slugs, and renders the right slug per locale?
Is there a better way to dynamically fetch and apply translated slugs during a language switch?
Are there any best practices for handling such multilingual nested routes in Next.js with Strapi?
My app is small for now, but I anticipate that I'll have more dynamic routes in the future, so I want to handle internationalization properly from the start.
I am open to improving my API structure or Next.js implementation if necessary.
Any feedback, examples, or pointers to related issues would be highly appreciated.
Thank you in advance for your time and insights! 😊
Beta Was this translation helpful? Give feedback.
All reactions