Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
404 on new posts, after build-time, using Next.js and Sanity.io

My goal is to be able to add new posts the CMS(Sanity.io) after build-time, and for the site to be able to display received data on a provided slug using dynamic routes.

Everything works well in dev environment, but in production it seems the page can't use the new slugs provided from the CMS, and responds with a 404.

Here's my code getting the posts from the CMS, inside my [slug].tsx file.

[slug.tsx]

export const getStaticPaths: GetStaticPaths = async () => {
  const query = `
  *[_type=='post']{
    _id,
    slug {
      current
    }
  }`

  const posts = await sanityClient.fetch(query)

  const paths = posts.map((post: Post) => ({
    params: {
      slug: post.slug.current,
    },
  }))

  return {
    paths,
    fallback: 'blocking',
  }
}

export const getStaticProps: GetStaticProps = async ({ params }) => {
  const query = `
  *[_type=='post' && slug.current == $slug][0]{
    _id,
    publishedAt,
    title,
    description,
    mainImage,
    gallery[0]->{
      title,
      link,
      images,
      display,
    },
    slug,
    body
  }`
  const post = await sanityClient.fetch(query, { slug: params?.slug })

  return {
    props: {
      post,
    },
    revalidate: 10,
  }
}

When I add new posts in the CMS I immediately see the thumbnail come up on the website, with the correct image and other data, but when I click the thumbnail I get 404.

I hope someone can help me!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!