Skip to content

Security basics

404 on refresh: why your app's pages break on Vercel or Netlify

A 404 on refresh while the home page works means the host has no file for that address. The fix on Vercel, Netlify and Cloudflare Pages.

Vlad Tkachenko10 min read
Two windows of the same app. The one behind shows its page; the one in front has a refresh arrow and a red 404.

In short

  • A 404 on refresh means your host was asked for a file named after the page, and it has none. A click inside the app never asks the host, so the page worked until you reloaded it.
  • The fix is one rewrite rule: every address the host has no file for gets your app's page, with a 200. On Vercel it goes in vercel.json, on Netlify in public/_redirects.
  • Check package.json first. A Lovable app made from 13 May 2026 lists @tanstack/react-start, and for that kind of app the 404 means the host is not running its server part.

You built your app with Lovable, Bolt, Cursor or Claude Code and put it on Vercel or Netlify. The home page opens, and you click through to your pricing page. Then you press refresh, or a customer opens a link you sent them, and the page is gone. Vercel shows its own error page with 404 and the code NOT_FOUND on it. Netlify shows "Page not found" and "Looks like you've followed a broken link or entered a URL that doesn't exist on this site." The home page still opens every time.

That is a 404 on refresh, and on these hosts it has one cause: the host was asked for a file named after your page, and it has no such file. The page is still in your app. One rule on the host fixes it, and the rule has to answer with a 200. Two other fixes you will find in answers, switching to HashRouter and making your page the host's 404 page, make the page open for you and still leave Google with an address it will not index.

Think of your host as a reception desk with a list. On the list are the files your build produced: one page, index.html, and the scripts and pictures it loads. Your app's pages, such as /pricing or /orders/42, are rooms inside the building. Nobody at reception has a list of rooms. Once a visitor is through the main door, the app itself walks them from room to room.

What does a 404 on refresh mean?

It means your host was asked for a file called pricing, read its list, and found nothing by that name.

An app built with Vite is one page. Lovable's documentation says its apps made before 13 May 2026 "use React + Vite and build to static files", and a Bolt, Cursor or Claude Code project may use Vite too. When you click a link inside it, the app's router (React Router, in a React app) draws the new screen and writes the new address into the bar itself, through a browser feature called the History API. The host is never asked. In the building, that is walking down a corridor, and reception never sees you go.

A refresh sends the whole address, /pricing, to the host. So does a link somebody opens from an email, and so does Google's crawler. The host looks for a file called pricing, has none, and answers with a 404 and its own error page. The visitor is standing at reception asking for a room by its number, and reception only knows the main door.

The home page is the exception because its address, /, is the one the host knows: it answers / with index.html. So the home page always opens, and every other page opens only when you click your way to it.

Why does it work in the preview but not on the live site?

Because the preview runs on a server that answers every address with your page, and your host does that only once you tell it to.

Vite's development server is built for apps like this. Its appType setting defaults to 'spa', which Vite's documentation describes as "use SPA fallback": an address with no file behind it gets your page. Its preview command is set up the same way. Vercel and Netlify serve only the files your build produced. Vercel's guide to Vite apps says that deep linking, opening a page by its own address, "won't work out of the box".

A click stays inside your app. A refresh asks the host for a file called pricing, and the host has only index.html and the files it loads.

Which kind of app do you have?

Check one line before you add anything, because one kind of app needs a different fix.

Open package.json in your project (in Lovable, it is in the Code tab). If @tanstack/react-start is listed among its dependencies, your app is the newer kind. Lovable's documentation says apps made from 13 May 2026 use TanStack Start, which runs code on a server as well as in the browser, and that for those a 404 on a page opened directly means the host is not running that server part. The rule below is for the older kind. For yours, Lovable's guide to deploying outside Lovable covers what the host has to run, and points to TanStack's list of hosts that support it.

If @tanstack/react-start is not there and the project has a vite.config file, it is the older kind. Lovable's guide says a 404 when you open a nested page directly "usually means the host is missing the index.html fallback". That fallback is the rule below.

How do you fix a 404 on refresh?

Add one rewrite rule on your host: any address it has no file for gets index.html, with a 200. The address in the bar stays as it was, the app reads it, and the app draws the right page. In the building, reception gets a standing instruction: anybody asking for a room you have no file for comes in through the main door, and the app takes them to the room.

Vercel

Create a file called vercel.json at the top of your project, next to package.json, holding the rule from Vercel's guide to Vite apps:

{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}

The rule leaves your real files alone. Vercel's documentation says "precedence is given to the filesystem prior to rewrites being applied", so a script or a picture that exists is still sent as itself. A script that is missing falls through to the rule and comes back as your page, which shows up as a different error: a blank page and "Failed to load module script".

Netlify

Create a file called _redirects, with no extension, in your project's public folder, holding this one line:

/*    /index.html   200

The 200 at the end makes it a rewrite: the visitor gets your page at the address they asked for, and the address does not change. Netlify reads the file from the folder it publishes, which for a Vite app is dist. Vite copies everything in public into dist when it builds, so public is where the file starts. A _redirects file at the top of your project never reaches dist.

Cloudflare Pages

You may need no rule at all. Cloudflare's documentation says that if Pages "cannot find a static asset or a custom 404.html for a request, it falls back to the root index.html", and that "a top-level 404.html disables the fallback". So if a refresh gives a 404 there, look for a 404.html at the top of your build (in a Vite project, public/404.html) and remove it.

Then, on any host, deploy again, open a page other than the home page in a private window, and refresh it.

The rule lives in one file, and a later deploy without that file brings the 404 back on every page except the home page, so an uptime check that asks only for the home page sees nothing wrong. Reeve Monitor also checks the pages you add, and a page that starts answering "not found" is an alert.

Why not switch to HashRouter, or use your page as the 404 page?

Both make the page open for a person, and both leave Google with addresses it will not index. Each takes one change, which is why they turn up in answers to this error.

What you changeWhat a visitor seesWhat Google gets
A rewrite to index.html with a 200The page they asked for, at the same addressThe page, with a 200
Your page copied to the host's 404.htmlThe page they asked forA 404, so the page is left out of search
HashRouterThe page, at an address with #/ in itAddresses Googlebot "can't reliably resolve"
A redirect from every address to /Your home page, wherever they were goingYour home page

The second row is easy to take for a fix, because the page opens. A browser draws whatever page comes back, whatever status came with it, so your app loads and finds the right screen. Vercel's documentation says it serves a 404.html "with a 404 status code" for every address with no file behind it. Google's documentation says it does not index pages that answer with a 4xx code, and removes ones it had already indexed. In the building, reception lets the visitor in and stamps "not found" on their pass. The visitor reaches the room, and Google reads the stamp.

HashRouter keeps everything after the # in the browser, so the host only ever sees / and never answers 404. Google's guide to JavaScript sites tells you not to load different content from that part of an address, because Googlebot "can't reliably resolve the URLs". And a link you shared before the switch, with no # in it, still gets the 404.

A redirect sends the visitor to your home page and drops where they were going. A customer who opens a link to /orders/42 from your email lands on /.

What happens to an address that really does not exist?

After the rule, your app has to say so itself, because the host answers every address with a 200.

Vercel's documentation says so: "Because every request matches that rewrite, Vercel never serves 404.html." A mistyped address, /pricng, gets your page and a 200, just as /pricing does. In the building, reception now shows in anybody who asks for any room, including rooms that were never built. The app has to be the one that says there is no such room.

Vercel's answer is a catch-all route in your app that draws a "not found" screen. In React Router it is one line, placed below every other route:

<Route path="*" element={<NotFound />} />

Ask your builder to add one if your app has none, and to add <meta name="robots" content="noindex"> to that screen. Google's guide suggests that tag for error screens in apps like yours, and Vercel's note says search engines "can treat" a "not found" screen that answers 200 "as a soft 404".

After the rewrite, every address answers 200. Only your app can tell a real page from a mistyped one.

Knowing when a page stops opening again

Ask for more than the home page, because the home page is the one address that keeps opening when this rule is lost.

Reeve Monitor checks the pages you add as well as your home page, and tells you when one stops opening.

  • A page you added that starts answering "not found" sends an alert by email, Telegram, Slack or webhook.
  • It can check that words you choose, such as "Pay now", are on a page, so a page that opens on your app's "not found" screen is caught too. When your app draws its words with JavaScript, it looks in a real browser.
  • Added pages are checked every 5 minutes, or every 15 when they need a real browser. Your home page is checked every 60 seconds.
  • Every hour it also runs our full security check against the live app.

See what Monitor checks

What to do right now

What to do

  • Open a page other than the home page in a private window and refresh it. A 404 there, with the home page working, is this.
  • Look in package.json for @tanstack/react-start first. If it is there, the host has to run your app's server part, and the rewrite is not your fix.
  • On Vercel, add the rewrite to vercel.json. On Netlify, put /* /index.html 200 in public/_redirects. On Cloudflare Pages, remove a top-level 404.html.
  • Keep the 200. A copy of your page as 404.html, HashRouter, or a redirect to / each leave Google an address it will not index.
  • Give your app a catch-all "not found" screen, with a noindex tag on it.

If the browser shows its own error page instead of your host's, the request never reached your host at all, and what "This site can't be reached" means covers each code it prints.

FAQ

Why does my page work until I refresh it?

Because a click inside your app never asks the host for anything. The app draws the new screen and writes the new address into the bar itself. A refresh sends that address to the host, which looks for a file by that name, finds none, and answers 404.

Why does it work in the preview but not on Vercel?

Vite's development server answers every address with your app's page by default, so a preview running on it never shows the 404. Vercel serves only the files your build produced until you add a rewrite, and its guide to Vite apps says deep linking "won't work out of the box".

Should I switch to HashRouter?

It stops the 404, because everything after the # stays in the browser. It also puts #/ into every address, and Google's JavaScript guide says Googlebot "can't reliably resolve" links built that way. A rewrite on the host keeps your addresses as they are.

Will the rewrite break my images or scripts?

On Vercel, a file that exists is still sent as itself: its documentation says "precedence is given to the filesystem prior to rewrites being applied". Only addresses with no file behind them get your page.

Does a 404 on refresh hurt my Google ranking?

Google asks your host for each address directly, the way a refresh does, so it gets the 404 too. Its documentation says it does not index pages that answer with a 4xx code, and removes ones it had already indexed.

Written by

Vlad Tkachenko

Founder, Reeve

I spend my time looking at apps built with Lovable, Bolt, v0, Cursor and Replit, and at the short list of mistakes that keep turning up in them.

More about the author

Read next

All articles

Not sure where your own app stands?

Run a free scan and get a plain-language grade from A to F in about 20 seconds. No account, no card.

Scan your app free

Automated external check, not a full audit. Absence of findings is not a guarantee of safety.