Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

getstaticpaths errors after new posts

You can also use getStaticPaths with fallback to true.
And getStaticProps with revalidate whicth triggers incremental builds basiclly.
to avoid error after build
export async function getStaticPaths() {
  const res = await fetch(`${baseUrl}/wp-json/wp/v2/posts`)
  const posts = await res.json()
  const paths = posts.map(({ slug }) => ({ params: { slug: `${slug}` } }))
  return {
    paths,
    fallback: true,
  }
}

export async function getStaticProps(context) {
  const resPost = await fetch(`${baseUrl}/wp-json/wp/v2/posts?slug=${context.params.slug}`)

  const post = await resPost.json()

  return {
    props: {
      post,
    },
    revalidate: 10,
  }
}
 
PREVIOUS NEXT
Tagged: #getstaticpaths #errors #posts
ADD COMMENT
Topic
Name
9+2 =