Websites2 minutes to read

Why does my React site show a 404 when I refresh a page?

Diagnose a nested URL that works inside your app but fails on reload. Test the HTML fallback, missing assets and the frontend router separately.

Follow the request for the nested page

A client-side router can open /events/friday without asking the server for another HTML file. Reloading that URL makes a fresh HTTP request for the path. On a Bothosting static deployment, enable STATIC_SPA=1 when your router should handle extensionless paths through the root index.

Try the same address two ways. First enter through the home page and click the link. Then paste the complete nested URL into a new tab. If the first visit works and the second returns an HTTP 404, the server needs a matching published file or the frontend fallback. If both reach the app but show its own “page not found” screen, inspect the routes your frontend defines.

Choose a fallback or publish a real page

For a single-page app, save STATIC_SPA=1 in Variables and restart the static deployment. The server checks for the requested file and a directory index first. The fallback serves the root index for a missing extensionless path. Your JavaScript router then decides what the visitor sees.

For a multipage site, publish an actual file such as public/events/friday/index.html when that URL needs its own HTML. This gives a crawler and a visitor the event page directly. A site with separate HTML pages can leave the fallback off. Follow the static publishing guide to set the public root.

Check the route and a deliberately missing asset

Reload the nested page. In the Network panel, inspect the first document response, then check what appears after the app starts. The document should return HTML and the router should display Friday’s event. Request a made-up filename ending in .js under the same hostname. The Bothosting static server should return 404 for that missing asset. This catches a setup that appears healthy only because every request receives the home page.