Page Refresh on Surge with React and React-Router

For some reason, this took me way much longer than it should have for such a simple solution. My app was working fine in development on page refreshes, something that React automatically does every time you save a file. But when I uploaded my project to Surge, I could not for the life of me figure out why it kept crashing when I refreshed the page. It kept leading me to a 404 page on page refreshes.

I initially found an article about using node.js instead of a Rails backend, and thought I had to rewrite my entire project in node.js and learn it, just to get my page refresh to work. This sounded absurd to me and I thought there had to be another way.

Lo and behold, after a month or more of searching for a solution,

All I had to do was change my index.html file after I run npm run build in my build folder to 200.html.

This was an absurdly simple fix and now my websites are not crashing on page refreshes after uploading to Surge.

Programming, people!

Stay sound, stay safe, and we’re going back in!