Next.js Discord

Discord Forum

generateStaticParams if page found it throw 500 not 404

Answered
Brown bear posted this in #help-forum
Open in Discord
Brown bearOP
how to throw 404
Answered by White-crowned Sparrow
I only managed to throw a 404 with the notFound() page which doesnt accept any data and its static
View full answer

20 Replies

White-crowned Sparrow
I only managed to throw a 404 with the notFound() page which doesnt accept any data and its static
Answer
Brown bearOP
like that?
White-crowned Sparrow
I dont know if this is working from the generateStaticParams()
I am calling this from inside my page.tsx
are u using the app directory or the page ?
Brown bearOP
app
White-crowned Sparrow
me too. But now u have to create a file called not-found.tsx next to your page
Brown bearOP
if I have in the paraent folder
parent
White-crowned Sparrow
export default async function NotFound() {

  return (
    <>
    Errorrrr PAGE
    </>
  );
}
so i guess it has to be inside the app folder, on the first level
Brown bearOP
works thankss
White-crowned Sparrow
Problem is that the notFound() doesnt accept any data. If u want to consume data from ur API tell me to explain my solution
in the last comment i have pasted my whole code
after 2 weeks of burning my self i managed to that. Dont know if its the best approach but it works
@Brown bear how to throw 404
you can also do export const dynamicParams = false
see the documentation on segment route configs for mroe details
White-crowned Sparrow
what ?