Next.js Discord

Discord Forum

Not Found message from Route Handlers

Unanswered
Milkfish posted this in #help-forum
Open in Discord
MilkfishOP
Hi guys, trying to return a Not Found from a GET request in a route handler.

The 404 does get sent, but it returns a blank page instead of the contents of the not-found file.

Not sure if this is a bug, or by design of the API - but is there a way to make this work without importing the not-found file into the route handler itself?

12 Replies

If you simply return a response with status 404, it will be treated like any other responses with any other statuses and the not-found file is not triggered
MilkfishOP
That's what I assumed too - doesn't seem to be the case
Minimal reproduction, where it shows that notFound only returns a blank page from within a route handler
MilkfishOP
Yep....... not sure if I should raise a bug report, or if it's a feature haha
if you need the 404 page, ig you should redirect to any non-existent page
redirect("/404")
MilkfishOP
Yep - that was my last resort, the 404 URL doesn't make a tonne of sense in this instance, so will have to revisit