How can I return 404 status code in React (with react-router-dom)?
<Route component={NotFoundPage} path="*" />
The answers I got can return a 404 page, but not the http status code. Is there any way around that?
How can I return 404 status code in React (with react-router-dom)?
<Route component={NotFoundPage} path="*" />
The answers I got can return a 404 page, but not the http status code. Is there any way around that?
React runs on the client. Under normal circumstances, you can't generate a 404 error response because there is no request or response at all.
If you were using some server-side renderer (such as Next.js) then it would likely provide a method for generating a 404 error, but it would be specific to that SSR framework.
Your Js or any client side service doesnt return response with code. You can get 404 status code from server. In front end there is no way to send status code. Status code is sent by server depending on the request sent by Client side app.
© 2022 - 2024 — McMap. All rights reserved.