Open ohadbp opened 7 years ago
It's actually quite simple. After all the express.static
definitions in index.js, put in a catch-all that redirects non-static files to the index.html. React-router will then catch these and send the correct route:
const path = require('path');
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, './server/static/index.html'));
});
Hey,
first of all thank you for this tutorial - very helpful. One question tho, using this code if i go directly to http://localhost:3000/login , instead of going to '/' and then click on the topbar option - we get 404 since don't have this route on the server side.
One way to solve it is to move everything to server side rendering but i would like to avoid it. What would be the best way to solve this ? while keeping keep rendering on the client side
Thanks.