Skip to content
Discussion options

You must be logged in to vote

Update:
Since Next.js v10, you can return notFound: true from getStaticProps which allows the page to return a 404 status and 404 Page. Learn more here: https://nextjs.org/docs/api-reference/data-fetching/get-static-props#notfound

export async function getStaticProps(context) {
  const res = await fetch(`https://.../data`)
  const data = await res.json()

  if (!data) {
    return {
      notFound: true,
    }
  }

  return {
    props: { data }, // will be passed to the page component as props
  }
}

I'm assuming in your case you're asking this because you're using the fallback: true behavior in getStaticPaths?

404 is a state of the UI so you should render it based on the properties:

//…

Replies: 14 comments 46 replies

Comment options

You must be logged in to vote
13 replies
@Vince-vegas
Comment options

@procarrera
Comment options

@Pattygeek
Comment options

@aguilarm
Comment options

@parham-ab
Comment options

Answer selected by stormfar
Comment options

You must be logged in to vote
3 replies
@lukaszsobek
Comment options

@thadeucity
Comment options

@aguilarm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@morganfeeney
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@samstr
Comment options

@jnv
Comment options

Comment options

You must be logged in to vote
3 replies
@Emiliano-Bucci
Comment options

@canali83
Comment options

@fmnxl
Comment options

Comment options

You must be logged in to vote
1 reply
@alevosia
Comment options

Comment options

You must be logged in to vote
2 replies
@procarrera
Comment options

@fmnxl
Comment options

Comment options

You must be logged in to vote
4 replies
@tpperez
Comment options

@LucasReinaldo
Comment options

@tnganth
Comment options

@tnganth
Comment options

Comment options

You must be logged in to vote
13 replies
@robbertvancaem
Comment options

@Fi1osof
Comment options

@robbertvancaem
Comment options

@Fi1osof
Comment options

@pkellner
Comment options

Comment options

You must be logged in to vote
2 replies
@threehams
Comment options

@florianwalther-private
Comment options

Comment options

You must be logged in to vote
2 replies
@delbaoliveira
Comment options

@ashishkarki
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet