Hello,
Without out Paylaod CMS V3 I am able to get next-intl to work with Next.js the way I want with localized slugs.
Example: English: en/about French: fr/a-propos
Then if the user goes into the URL address bar and changes the prefix, user will go to the equivalent localized page and url.
Example: fr/about goes to fr/a-propos
Same if i hard code the path using English slug in the next-intl’s Link component.
Example:
<Link href=”/about”’>Link here</Link>
In the front end if user has chosen French and hover over that link it would say fr/a-propos.
This logic is handled with next-intl routing.js file’s pathname’s object
Example:
pathnames: {
'/': '/',
'/about': {
en: '/about',
fr: '/a-propos'
},
}
Now my main issue with the Payload CMS integration is that next-intl’s routing.js does not work properly if i have dynamic slugs that come from the DB.
In routing.js If i use
pathnames: {
'/': '/',
'/[slug]': {
en: '/[slug]',
fr: '/[slug]',
},
'/about': {
en: '/about',
fr: '/a-propos',
},
}
And then go to the page with this path: fr/a-propos
I get 404 error and also my language switcher stops working.
next-intl official docs does mention that the routing.js file is used with CMSs (https://next-intl.dev/docs/routing/configuration). In my case they don’t work.
Anyone know how to deal with this in a clean manner?
There are cases where I want to code in the URLs in the frontend source code.