Page Refresh on Surge with React and React-Router

Lawson Hung
1 min readAug 2, 2020

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!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Lawson Hung
Lawson Hung

No responses yet

Write a response