1

We have a handler for all non-specified routes:

<ReactRouter.Route path="*" component={Handle404} />

But this returns a 200. How can we return a 404 status code?

1
  • Are you using server side rendering?? If yes then this might be helpful. Commented Mar 9, 2017 at 16:03

2 Answers 2

2

We cannot send status code from client-side. For SPAs, when browser requests for page, it just downloads the javascript files and pages are rendered on browser side. Routing is handled purely on client-side. Even when we request server for 404 page, the request to download the page content is successful so it will be status 200 only. Eventhough actual page content is "Page not found".

If you need to send specific case you might want to hadle it at server-side. However, you can always create custom pageNotFound page.

Sign up to request clarification or add additional context in comments.

Comments

1

To send a status code of 404 to clients, you need to use a server side language such as node.js with express

React.js on the other hand is a front-end library, it is not a server side language, that's why it cannot do what you asked.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.