erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

Server return status 200 while rendering 404 page #990

Open c089 opened 8 years ago

c089 commented 8 years ago

Because of the catch-all route match will always match a route and renderProps will always be defined. For this reason, this branch is never reached and the 404 page is served with a status code of 200.

c089 commented 8 years ago

I'm facing the same issue in a project of mine. My current best idea would be to have different routes module on the client, that filters the 404 route. Pseudocode:

//server/routes.js
import routes from '../app/routes';
export default routes.filter(r => r.status !== 400);

Any better ideas?

c089 commented 8 years ago

Turns out we can use renderProps.route to search for a 404 route:

// given a route defined like this:
<Route status={404}/>
// in the match callback we can:
const is404 = renderProps.routes.find(r => r.status === 404) !== undefined;
Iuriy-Budnikov commented 8 years ago

+1

beku8 commented 8 years ago

+1

Iuriy-Budnikov commented 8 years ago

How to pass status for ex for this route: /collection/:id_product ???