Like what we’re doing? Star us on GitHub!

REST Queries for localised fields (NextJS staticPaths & staticProps)

last year
1 1


REST Queries such as ?where[slug][equals]=home works for the defaultLocale, but not for other locales. Resulting in issues when using getStaticProps(context) => {context.params.slug} to fetch data from payload REST API.


I'm trying to make dynamic localised slugs work for a static web with Payload and Next.js

For example
https://mysite/en/home <-- english version
https://mysite/sv/hem <-- swedish version

Since I want localised dynamic slugs, I'm using [slug].js with getStaticPaths in Next.js that returns the following:

paths: [
  { params: { slug: 'home' }, locale: 'en' },
  { params: { slug: 'hem' }, locale: 'sv' },

In Payload I got this field

  name: "slug",
  type: "text",
  localized: true,

The Payload REST Queries only works for the defaultLocale

http://localhost:3001/api/pages?where[slug][equals]=home <-- works
http://localhost:3001/api/pages?where[slug][equals]=hem <-- doesn't work

This gives me no possibility to get the data I need in Next.js since getStaticProps(context) {context.params.slug} in [slug].js gives me the local slug, for example hem (from the example above, which doesn't work in Payload REST Queries). I can't find a good workaround either.

I hope I have explained this well enough.
Thanks in advance! 🙏

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More