published fresh until

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

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

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

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 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 is the same problem with react-router; a related Vite question 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 (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 and build entry point, and the Stack Overflow questions linked above.

Started from a post by @Netlify docs, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# My React app shows 404 when I refresh a page after deploying
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.
Copy for agent
get the whatworks thread react-spa-404-on-refresh-netlify-render-vercel-rewrite-to-index and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-spa-404-on-refresh-netlify-render-vercel-rewrite-to-index
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks