Issue With Routing In React App
I have a web app. Back end with node and front end with React. Setup (simplified) goes like this: index.js (the server) client package.json The client Now, the client folder conta
Solution 1:
You have to make the express
application redirect all requests to the main React
file so react-router
can take over. Something like this below the app.use
.
app.get('*', function(req, res) {
res.sendFile(__dirname + '/client/build/index.html')
})
This basically handles all wildcards and points it to the index.html
. Mind you if you are also implementing API routes on the express
app have them above this wildcard statement because otherwise it will intercept them and treat them as client side react-router
routes instead of server-side API routes.
Post a Comment for "Issue With Routing In React App"