Monday 30 April 2018

Getting a 404 error on reloading a react app served with express

Hi, I have this website I built with the mern stack and it's hosted on heroku, here https://ift.tt/2FsDUiy website works fine if you follow the above link. You can also navigate to all the pages, but if you try to reload any page that is not the homepage or follow a direct link to a page like this, https://ift.tt/2KpfLwM, you get a 404 error, cannot get /page/ ...I tried solving the issue by adding the below code to my server.js file, but the routing fails app.get('*', (req, res) => {res.sendFile(path.join(__dirname+'/client/build/index.html'));});Please I will appreciate any advice on how to solve this. Thanks

Submitted April 30, 2018 at 10:20AM by myrrtle

No comments:

Post a Comment