App router can't answer anything but http status 200 #70170
Unanswered
iliaschaumont
asked this question in
App Router
Replies: 2 comments
-
I reproduce with a very small configuration :
A catchall route that returns notFound all the time. It displays the 404 page but still returns 200 code. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Alternatively, tried others next/navigation methods to see if they work and... I'm afraid not as documentation says.
When accessing localhost:8081/en/foo I am redirected to /en/about BUT with a 200 status code. Documentation says these methods should handle specific status codes so I'm very confused |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR : can't manage to return anything but 200. Got workaround below but definitely prefer cleaner option
Hello
I use the app router with Next14. I have a dynamic route based on the id of items in my DB. I do Server Side fetching, so I do my data fetching in the export default of my file /app/[locale]/show/[id]/page.jsx
After I do getDataFromDB(id) I would like to return a 404 response if I didn't get anything because users and other softwares such as Google SEO should know "not everything went well". I use the "notFound()" function from next/navigation.
When I look at my app logs I always see that my frontend answers with a 200, even if the url doesn't make any sense ("localhost:8081/en/show/thisisreally444notan234id/ANDEOHVEOZFO").
User see the 404 page from my not-found.jsx file, but the http code is always 200. I used postman to check, and the http code is truly always 200.
I really struggle with this because that means I can't provide a relevant status code and my SEO is dead because I can't return proper 404 or 410.
Any way to do this with app router ? What hidden gem in the documentation or discussions did I miss ?
Considered workarounds:
Thanks for giving any help or tips 🙏 that'd be very appreciated !
Beta Was this translation helpful? Give feedback.
All reactions