How do i get status code 404 for not-found page? #61486
Replies: 4 comments 4 replies
-
Is your page streaming in data? Streamed pages will still 200: https://nextjs.org/docs/app/api-reference/file-conventions/not-found |
Beta Was this translation helpful? Give feedback.
-
Just had the same issue, I had a 'use client' provider wrapping the app that was also importing a component using |
Beta Was this translation helpful? Give feedback.
-
make sure you have few solutions I came up while encountering this issue:
|
Beta Was this translation helpful? Give feedback.
-
Hi there, I hope this helps someone resolve the issue faster than I did — I spent quite a bit of time figuring it out. The key takeaway: make sure you don’t start streaming anything before calling Here are my overall findings. Next.js App Router – Reliable 404/500 Headers Checklist 1. Do all data-fetching inside the page component (or its children)
2. Call notFound() / throw before streaming starts
3. Beware of
4. Layouts may await, but must not stream JSX to the client prematurely
5. Middleware considerations
6. Static/ISR vs Dynamic
6. After code changes, restart dev server or rebuild
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
How can I ensure that a not found page returns a 404 status code? Dynamic pages return a 200 status code, but for pages not defined in the app router, it returns a 404.
Example from vercel repo:
Repo - https://github.com/vercel/next.js/tree/canary/examples/cms-sanity
Page not defined in app router - https://next-blog-sanity.vercel.app/pasdasd returns 404
Dynamic page with notFound() method - https://next-blog-sanity.vercel.app/posts/learn-hasdasd returns 200
Edit: Sorry, even though that repo is not using App Router, the problem is still relevant.
I understand that the 404 page is displayed correctly, but I also need to ensure that the server returns a 404 status code for SEO purposes.
Thanks in advance!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions