Next.js Discord

Discord Forum

Can't Return a 404

Unanswered
Rex posted this in #help-forum
Open in Discord
RexOP
I'm having a nightmare just trying to return a 404 when a route doesn't exist in Next 13 and app router.

I've tried with & without a custom 'not-found', the network response is always 200.

Can anyone offer any advice please?

22 Replies

to get things strait, you don't have a page.tsx/route.tsx file and going to the route doesn't produce 404 in network tab?
or are you using notFound() inside a file
RexOP
I'm using a dynamic route with an id. I'm trying 'if (!id) notFound()', this returns the built in not-found route, or the custom not-found as it should but the status code is always 200.
that doesn't sound good
RexOP
It's not 🤣
and have you made sure to use latest version and possibly canary
RexOP
I'll update and try again.
whan i was trying to see an example of it doing it i found this: https://nextjs.org/docs/app/building-your-application/routing/dynamic-routesa, but it is the only case that i could find (strange)
RexOP
I'm told it's something to do with streaming and non-streaming routes. If the route is streaming then there will always be a 200 code returned. But how to make it non-streaming?
I've updated to the latest release and still have the same issue sadly
RexOP
I was using loading, but have removed it after reading this, and still getting a 200 code. 😭
yeah you may be onto something:
When streaming, a 200 status code will be returned to signal that the request was successful.

The server can still communicate errors or issues to the client within the streamed content itself, for example, when using redirect or notFound. Since the response headers have already been sent to the client, the status code of the response cannot be updated. This does not affect SEO.
[[source](https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming#status-codes)]
RexOP
Funny that they say this doesn't affect SEO, not being able to return a 404 certainly does affect SEO
its because you are meant to throw the notfound in generatemetadata i think
RexOP
Is it? Let me check
Nah, not that.
i mean, that is all thought streaming was... try deleting your .next folder to make sure that it hasn't kept old files (its just cache, so nothing should go wrong)
RexOP
That's ridiculous if that's the case. I'll keep trying. Thanks for the help 👍