Thomas Osayi

November 22, 2026 · 10 min read · Thomas Osayi

Why your React app shows 404 on refresh on Vercel, and how to fix it

Your React or Vite app works until someone refreshes or opens a shared link, then Vercel or Netlify shows 404. Why it happens and the exact rewrite rules that fix it.

The app looks finished. You click around, every page loads, and then someone texts you a link to the pricing page and it opens on a plain white screen that says 404: NOT_FOUND. Or you press refresh on the dashboard and the whole thing disappears. It is one of the first problems people hit after deploying an app made in Lovable, Bolt or Cursor to Vercel or Netlify, and it has nothing to do with the code they wrote.

The cause is one missing config file. Here is why it happens, the exact rules for each host, why the fix sometimes seems not to work, and what to check once the 404s are gone.

Why does my React app show 404 when I refresh the page?

Because the host is looking for a file that does not exist, and your React router never gets a chance to run.

A React app built with Vite is a single page app. The build step produces one HTML file, index.html, plus a folder of JavaScript and CSS. When you open the site at the root URL, the host serves index.html, the JavaScript loads, and React Router reads the address bar and draws the right screen. When you click a link inside the app, React Router changes the URL using the browser history API and swaps the screen. No request goes to the server at all.

A refresh is different. The browser sends the full path, say /dashboard/settings, to the host. The host does what static hosts do: it looks for a file called dashboard/settings or dashboard/settings/index.html in the build folder. There is no such file, because the only page that exists is index.html. So the host answers 404 before any of your JavaScript loads.

That is why the bug feels random. It only appears on refresh, on links opened from email or chat, on bookmarks, and on any URL typed straight into the address bar. Every one of those is a direct request to the host.

How do I fix 404 on refresh on Vercel?

Add a vercel.json file at the root of the project with a rewrite that sends every path to index.html.

Vercel's own Vite guide says deep linking will not work out of the box for a single page app, and gives this configuration for a file named vercel.json:

{ "rewrites": [ { "source": "/(.*)", "destination": "/index.html" } ] }

A rewrite is not a redirect. The address bar keeps showing /dashboard/settings, while Vercel quietly serves the contents of index.html. React Router then loads, reads the path, and shows the settings screen as if the user had clicked their way there.

Where the file goes

The file sits next to package.json in the folder Vercel builds. For most AI-built apps that is the repository root. If your project lives in a subfolder, check Settings, Build and Deployment, Root Directory in the Vercel dashboard, and put vercel.json in that folder instead.

If cleanUrls is on

Vercel's docs add one note: if cleanUrls is set to true in vercel.json, drop the file extension, so the destination becomes / rather than /index.html.

Deploy again

Config changes only apply to new deployments. Commit the file, push, and wait for the new build to finish before testing. Then open a deep URL in a private window so nothing cached gets in the way.

Why did my vercel.json rewrite not work?

When the rewrite seems to do nothing, it is almost always in the wrong place, in the wrong project, or overridden by something else.

These are the causes I check, in order:

  • The file is in the wrong folder. A vercel.json inside src or public is ignored. It must be at the root Vercel builds from.
  • The file name is wrong. Vercel.json, vercel.JSON or vercel.json.txt (a common one on Windows with hidden extensions) will not be read.
  • The JSON is invalid. A trailing comma or a missing quote makes Vercel fail the deployment or ignore the file. Paste it into any JSON validator if unsure.
  • The framework preset is wrong. If the project was imported with the Next.js preset but is really a Vite app, the output directory and routing assumptions are off. Set the preset to Vite, the build command to npm run build and the output directory to dist.
  • You are testing an old deployment. Preview URLs are tied to a specific build. Open the latest deployment from the dashboard, not a link from yesterday.
  • Another rule matches first. If you added redirects or headers in the same file, read the whole file. Older configs sometimes use a routes array, which cannot be combined with rewrites.

If none of that explains it, open the deployment in the Vercel dashboard and look at the Source tab to confirm vercel.json is actually part of the build.

How do I fix it on Netlify?

On Netlify, add a file named _redirects with the single line /* /index.html 200, and make sure it ends up in the published folder.

Netlify's documentation describes exactly this rule for apps that use the history pushState method. The 200 status is what turns the rule into a rewrite instead of a redirect, so the visitor keeps the original URL. The same rule can live in netlify.toml as a redirects block with from set to /*, to set to /index.html and status set to 200.

The detail that trips people up is the location. The _redirects file must be in the folder Netlify publishes, which for Vite is dist. But dist is rebuilt from scratch every time, so a file dropped there by hand disappears. Put _redirects in the public folder at the project root. Vite copies everything in public into dist during the build, so the rule ships with every deploy.

Netlify also documents a behavior called shadowing. By default a rewrite will not replace a file that actually exists, so /logo.png still serves the image even with the catch-all in place. That is what you want for a single page app. If you have other redirect rules, Netlify suggests keeping the catch-all as the last line, because rules are read top to bottom.

What about Firebase Hosting and other hosts?

Every static host needs the same idea, a rule that serves index.html for unknown paths, but each one spells it differently.

On Firebase Hosting, running firebase init hosting asks whether to configure the site as a single page app. Answering yes writes a rewrites entry into firebase.json that sends all paths to /index.html. If you said no the first time, you can add that entry by hand and redeploy. On a server you control, such as Nginx, the equivalent is a try_files directive that falls back to index.html.

The point to remember is that this is always a hosting setting, not something you can fix inside React. No change to your routes, components or App.tsx file will stop a 404 that the host returns before your code loads.

Does the catch-all rewrite break assets, APIs or SEO?

It does not break assets or API routes on Vercel or Netlify, but it changes what a missing page looks like, and you should handle that.

Real files win. Both hosts serve an existing file before applying a catch-all rule, so your JavaScript bundles, images and favicon load normally. Serverless functions in an api folder on Vercel are also matched before the rewrite. If you proxy part of the site to an external API, put that rule above the catch-all so it is checked first.

What changes is the behavior for pages that genuinely do not exist. Before the fix, /nonsense returned a 404. After it, /nonsense returns index.html with a 200 status, and React decides what to show. If your router has no catch-all route, users see a blank page or a broken layout. Add a final route with the path * that renders a not found screen with a link home.

For search engines, a single page app has a bigger issue than status codes: the HTML that arrives is mostly empty until JavaScript runs. That is fine for a logged-in dashboard. For marketing pages that need to rank, consider prerendering or moving those pages to a framework like Next.js. I cover that trade-off in "Vercel build failed? The most common Next.js deploy errors and fixes" and in "How to move a Lovable app to Vercel and your own domain".

Should I just switch to HashRouter?

You can, and it will stop the 404s, but it is a workaround with real costs, so I only use it when the host cannot be configured.

A hash router puts the route after a # in the URL, like example.com/#/dashboard. Browsers never send the part after the # to the server, so the host only ever sees a request for the root and always serves index.html. No rewrite needed.

The costs:

  • URLs look dated and are harder to share or read aloud.
  • Analytics tools and ad platforms often treat every hash URL as the same page.
  • Search engines generally ignore the part after the hash, so hash routes cannot be indexed as separate pages.
  • Switching later breaks every link people have already saved.

On Vercel and Netlify, where a rewrite is one small file, the browser router plus a rewrite is the better choice. Hash routing makes sense for something like a static file share or a host that offers no rewrite setting at all.

Here is an illustration with a made-up business. A small studio builds a booking app in Lovable, exports it to GitHub and deploys it on Vercel. Booking works when tested from the homepage. A week later, clients start replying to the confirmation email saying the "manage your booking" link is broken. The link points to /bookings/8f2c, and every client who taps it sees 404: NOT_FOUND.

Nothing is wrong with the booking code. The studio owner always started from the homepage and clicked through, so React Router handled every navigation. Clients come in cold from email, which is a direct request to Vercel.

The fix takes three steps. Add vercel.json at the repository root with the rewrite above, push, and wait for the deployment. Then add a catch-all route that shows "We could not find that page" with a button back to the homepage, so a mistyped booking ID no longer shows a blank screen. Finally, test four URLs in a private window: the homepage, a booking page, a nested settings page and a made-up path.

This kind of deep link problem matters on any site where people land on inner pages. On the LACEUP storefront, for example, product pages get shared and opened directly, so each one has to load from its own URL.

A product page I built for the LACEUP basketball apparel storefront, with a size selector and add to bag button
A product page I built for the LACEUP basketball apparel storefront, with a size selector and add to bag button

When should I get help with this?

If you have added the rewrite, redeployed, and still see 404s, or the app has a custom server mixed in, it is worth having someone look at the project settings directly.

Most cases are a five minute fix once the cause is clear. The slow part is usually finding which of several overlapping configs is in charge: a vercel.json from one tool, a netlify.toml from another, and a framework preset that does not match the code. AI builders sometimes generate config for a host you are not using, and those files sit in the repo confusing everyone.

I handle this as a Quick Fix, from $60 with a two day turnaround. If the 404 is one item on a longer list, like environment variables, auth redirect URLs and a broken webhook, the Fix Plus Features package from $200 covers up to three fixes plus one small feature. Apps that work but need the launch details finished, from domain to production keys, fit Finish and Launch from $600. The "fix your Lovable app" page explains what I check first.

The bottom line

A 404 on refresh in a React or Vite app means the host does not know that every path belongs to index.html. On Vercel, add vercel.json at the project root with a rewrite from /(.*) to /index.html. On Netlify, put a _redirects file with /* /index.html 200 in the public folder. Redeploy, test deep URLs in a private window, and add a not found route so unknown paths still show something useful. It is a small file, but it is the difference between a demo that works when you click around and an app that works when real people open the links you send them.

Questions, answered in one line

Why does my React app work when I click links but 404 when I refresh?

Clicking a link lets React Router change the URL in the browser without asking the server, but a refresh sends the full path to the host, which has no file at that path.

Where do I put vercel.json for a Vite app?

Put it in the root of the project that Vercel builds, which is the folder set as Root Directory in the project settings, next to package.json.

Does the Netlify _redirects file go in the dist folder?

Put it in the public folder of a Vite project, because Vite copies everything in public into dist at build time, and a file placed directly in dist gets wiped on the next build.

Will a catch-all rewrite break my images or API routes?

Normally no, because both Vercel and Netlify serve real files first, but rules for proxies or external APIs should sit before the catch-all rule.

Does Next.js have this problem?

No, Next.js generates a route for each page and Vercel understands its routing natively, so the 404 on refresh problem is specific to single page apps built with tools like Vite or Create React App.

Can someone fix this for me quickly?

Thomas Osayi fixes single bugs like a 404 on refresh through his Quick Fix package, from $60 with a two day turnaround.

Sources

About the author

Thomas Osayi is a full-stack developer in Los Angeles studying computer science at Loyola Marymount University. He founded and built SQWAD, a SaaS platform Shopify brands use to run creator programs, and builds custom Next.js websites, SaaS MVPs and fixes for AI-built apps for businesses and founders.

See his work · Services and prices

Related articles

Fix, finish and launch your AI-built app

Built your app with Lovable, Bolt, v0, Replit or Cursor and got stuck? I fix the bugs, connect auth and payments, clean up the code and deploy it to production.

See the service