Next.js Discord

Discord Forum

How to return 404 error if the requested document is not found by the server?

Unanswered
Great Dane posted this in #help-forum
Open in Discord
Great DaneOP
I use server components (app router). If the server response is successful (record found in the database), then the page loads. If the record is not found or other server error, then the special errorboundary page is loaded. I used it at the development stage and this is a convenient tool. The problem is that after deploying the site, some pages can be indexed by search engines. If after time the page is deleted, then Google must get an error to remove the page from it's index. Is it possible to configure so that in case of an error, the correct code (404) will return and page 404 will be loaded? Thanks for any help.
P.S. I cannot put the whole code here, since it is too long, so I bring a link to another resource. I don’t know if the links are allowed here, but I have no way out and I need help.
The link: https://stackoverflow.com/questions/77407105/how-to-redirect-to-404-page-with-error-status-code-in-next-js

0 Replies