Page not found when you refresh
Clicking works, refreshing breaks. The browser asked the server for a file that only exists inside your JavaScript router.

Key takeaways
- Single-page apps route in the browser; a refresh asks the server for a path it has no file for.
- The host must answer unknown paths with index.html (a fallback), so the router can take over.
- A custom 404 page in the wrong place, or a route that only exists after login, can look like the same bug.
- Test by pasting a deep link into a new private window, not by clicking from the home page.
If your app loads fine from the home page and every link works, but refreshing on a page like /dashboard or /products/42 shows "404 Page not found", the cause is almost always single-page app routing without a server fallback. Your router lives in JavaScript, so clicking a link changes the address without asking the server for anything. A refresh, a bookmark or a shared link sends the full path to the server, which looks for a file named /products/42, finds nothing and answers 404. The fix is to make the host serve index.html for any path that is not a real file, so the router can draw the right page.
Why clicking works and refreshing does not
Startbase web apps are React single-page apps built with Vite (SEO guide explains what that means for crawlers too). After the build, the published site is a handful of files: one index.html, some JavaScript and CSS bundles, and your images. There is no file for each page. The router reads the address bar and renders the matching screen.
- Click a link: the router updates the address with the History API. No request for /products/42 ever reaches the server.
- Refresh or paste the link: the browser asks the server for /products/42 directly. If the host has no rule for it, you get its 404.
Hosts handle this differently. Cloudflare Pages, which serves Startbase published sites, treats a project as a single-page app and serves the root page for unknown paths when the build has no top-level 404.html. That default means the bug usually appears only when something changes that behavior, which is why the causes below are ranked the way they are.
Causes, most likely first
1. A 404.html in the build output
Someone asked for "a nice 404 page" and the agent created a static 404.html file in public. On hosts that use the presence of that file to decide between "static site" and "single-page app", it switches the fallback off: every deep link now gets the 404 page. Check: look in the Code tab for public/404.html or any 404.html that ends up at the root of the build. Fix: delete the static file and render the not-found screen inside the router instead, as a catch-all route.
2. A redirects or headers file that overrides the fallback
A _redirects file (or similar host config) added for one redirect can include rules that send everything else to a 404 or to the wrong place. Check: search the project for _redirects and read every line. Fix: if you need an explicit rule, the common single-page pattern is "/* /index.html 200" placed last, so real files and your specific redirects match first. Ask the agent to confirm the format for the current host before adding it.
3. The route does not exist, or only exists after sign-in
Not every 404 is a server 404. If the page that appears is your app's own not-found screen (your styling, your nav), the server did its job and the router has no match. Typical reasons: the path changed (/product/42 versus /products/42), the route is registered only after auth state loads, or a nested route lacks its parent. Check: compare the address with the route list in the router file. Fix: register protected routes always, and inside them show a loading state while the session resolves, then redirect to sign-in if there is none.
4. Hash routes versus path routes
An app that switched from hash routing (/#/products) to path routing (/products) keeps old shared links alive only if both work. Old links with # always load index.html and should be fine; new path links depend on the fallback above. If you swapped the other way, path bookmarks break. Pick path routing for anything public: it is cleaner for links and search engines.
5. Assets requested with relative paths from a deep page
Sometimes the fallback works but the page is blank on refresh: index.html loaded at /products/42 asks for "assets/index.js" relative to /products/, gets index.html back instead of JavaScript, and nothing renders. Check: the browser console shows "Unexpected token <" or a MIME type error. Fix: make asset paths absolute from the root (a base of "/" in the Vite config).
6. Capital letters and trailing slashes
Servers and routers can treat /About and /about, or /pricing and /pricing/, as different paths. A link someone typed by hand, or an old link from a newsletter, may not match the route even though the page exists. Check: try the failing link in lowercase and without the final slash. Fix: keep every route lowercase, and have the router redirect the variants to one canonical form instead of showing not found.
How to test it properly
- 01Publish (the live site only changes when you publish or republish, publish docs).
- 02Open a private window and paste a deep link such as your-app.startbase.app/settings/profile directly.
- 03Refresh three different pages, including one that needs sign-in, and one with an ID in it.
- 04Try a path that should not exist, like /zzz. You want your app's own not-found screen with a link home, not a host error.
- 05Repeat on your custom domain if you use one, since that is the address people share.
The workspace preview is a development server, which usually has the fallback built in. A preview that refreshes fine proves little about the published site; always test the live address.
The message to send the agent
On the published site, refreshing /orders/123 or opening it from a shared link shows a 404, but clicking to it from the home page works. Check the build output for a static 404.html, any _redirects or host config file, and the Vite base setting. Make every unknown path serve index.html so the router handles it, keep real files and assets served normally, and render a styled not-found screen from a catch-all route with a link back home. Make sure protected routes show a loading state while the session loads instead of a not-found screen.
Then republish and run the private-window test above. If the problem started after a specific change, the Versions list shows each build; restoring the version from before the 404 page was added is a quick way to confirm the cause (versions docs).
Why this matters beyond annoyed users
Search engines and link previews request deep URLs directly, exactly like a refresh. If those return 404, the pages will not be indexed and shared links show no preview. The opposite mistake also hurts: a fallback that answers 200 for every made-up path makes junk URLs look like real pages. Have the catch-all route set a noindex tag on the not-found screen. The SEO guide for your app and the canonical URL glossary entry cover the rest.
Frequently asked questions
Why does my React app show 404 on refresh?
React Router and similar routers change the address in the browser without asking the server. On refresh, the server is asked for that path, has no file for it, and answers 404 unless it is set to fall back to index.html.
Is using hash routing (#) a good fix?
It works because everything after # never reaches the server, but it makes ugly links and is worse for search. Fixing the server fallback and keeping normal paths is better for public sites.
Refreshing works in preview but not on the live site. Why?
The preview runs a development server that falls back to index.html automatically. The published site is static files on a host, so the fallback depends on the build output and any redirect or 404 files in it.
Will a catch-all fallback hide real errors?
It can make every unknown path return your app with a 200. Render a clear not-found screen for unmatched routes and mark it noindex so search engines do not treat it as a page.

