React Router failing on Heroku

I found this question asked before, but it was a couple of years ago and I don’t believe it was sufficiently answered. I made an app with React and Express using React Router. When I deployed it to Heroku, navigating with links works just fine, but manually typing into the address bar in the browser gives an error, "Cannot GET /whatever". It’s as though the request is being sent to the Express server and not React Router. Has anyone else experienced this, and is there a potential fix to this problem?
The app is here if you’d like to recreate the problem for yourself, and a Github repo can be found here.

@LuosRestil If you do the same thing locally, I expect you to have the same results. Do you have your code on GitHub, so we can take a look and offer some suggestions? Without seeing how your app is structured, it is difficult to diagnose the exact cause of the issue. React is an SPA. I assume you are using React Router or something like it for the various “routes”. The express server does not know anything about those routes, so if you try to go directly to a route only used by the client, you will get a 404 error (what you are currently seeing).

There are several ways to handle what you are seeing. I found this Stack Overflow thread that summarizes the pros and cons of various methods.

Using a static.json file might work. You can also check the create-react-app deployment docs serving-apps-with-client-side-routing and heroku.

Strangely, this problem only presents itself once it’s deployed to Heroku or if I use the Heroku CLI command, “heroku local”. Maybe it’s because I haven’t run the React “build” command while I’m testing it on my machine? I’ve updated the post to include the suggested Github link. Thanks for the resource suggestion, I’ll give it a look.

Thanks for the suggestions, I’ll take a look!

In case anyone else runs into this, I wound up using the solution outlined here, and learned the root cause of the problem from the Stack Overflow link in @RandellDawson 's solution. All up and running now! Thanks again for the help!