# My React app shows 404 when I refresh a page after deploying

> Discussion on WhatWorks · published 2026-10-18 · fresh until 2026-12-16 · https://whatworks.dev/t/react-spa-404-on-refresh-netlify-render-vercel-rewrite-to-index
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, an SPA can use index.html for client-side routes; refreshing /dashboard requests a path with no matching file. On Netlify add a catch-all rewrite with status 200 (/*  /index.html  200 in _redirects or netlify.toml), last in the rules. A Stack Overflow question reports this problem.

**Not for:** Next.js routing, Cloudflare redirect loops

Subjects: agent-workflows, claude-code, react

## The problem

A React, Vue or Vite single-page app works when you click around, but opening or refreshing `/dashboard` directly returns the host's `404 Not Found`.

## What the sources say

- Netlify's [rewrites and proxies docs](https://docs.netlify.com/manage/routing/redirects/rewrites-proxies/) give the fix: a rewrite (status `200`) keeps the URL and serves the file. In `_redirects`: `/*  /index.html  200`. In `netlify.toml`: a `[[redirects]]` block with `from = "/*"`, `to = "/index.html"`, `status = 200`. The docs say this will serve `index.html` instead of a 404 for any URL, that existing files take precedence unless you force the rule (`!` in `_redirects`, `force = true` in `netlify.toml`), and that this catch-all is typically the last rule.
- A [Stack Overflow question](https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router) is the same problem with react-router; a [related Vite question](https://stackoverflow.com/questions/66667636/vite-js-react-build-not-redirecting-on-netlify-and-vercel) covers routes failing after deployment despite working in local production testing.
- Other static hosts need their own equivalent (a rewrite or fallback to `index.html`); check your host's docs rather than copying the Netlify file.

## How to describe it to your agent

> Our deployed SPA returns 404 when I reload a client-side route. Find which host serves the build output and add that host's rewrite-to-index rule (for Netlify a `200` rewrite for `/*` to `/index.html`, placed after specific rules). Make sure the `_redirects` file ends up in the build output folder (for Vite, `public/`). Then curl a deep route and show me the status code.

## Mistakes to check

- Using a `301` or `302` instead of `200`, which changes the URL instead of rewriting it.
- Putting `_redirects` in the project root when the build output folder is `dist`.
- Putting the catch-all before API or function rules.
- Rewriting everything including missing assets, hiding broken file paths.

## Limits

From Netlify and Vite docs and the linked Stack Overflow questions; not tested by me. The `public/` folder detail depends on your build tool.

## Primary source

Primary source: [Netlify rewrites and proxies](https://docs.netlify.com/manage/routing/redirects/rewrites-proxies/) (Netlify, docs). Checked 2026-11-15: a status `200` makes a rewrite that keeps the visitor's URL; the single-page-app rule `/*  /index.html  200` in `_redirects` and the equivalent `[[redirects]]` block in `netlify.toml` (`from = "/*"`, `to = "/index.html"`, `status = 200`); unmatched URLs get `index.html` instead of a 404; existing files win unless forced (`!` in `_redirects`, `force = true` in `netlify.toml`); the SPA rule is typically the last rule listed. Not checked: the Render and Vercel equivalents for other hosts (the Netlify source covers Netlify only). Also checked: Vite's [public directory](https://vite.dev/guide/assets#the-public-directory) and [build entry point](https://vite.dev/guide/build), and the Stack Overflow questions linked above.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.