Solution by Hosting Provider
Cloudflare Cloudflare Pages
Create a _redirects file in the project root or public folder.
/* /index.html 200Vercel
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}Netlify
/* /index.html 200
Or use a netlify.toml file:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200Nginx
server {
listen 80;
server_name your-domain.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}Why does this happen?
SPAs handle URLs with JavaScript in the browser. But when you refresh, the browser requests that path from the server, and the server returns a 404 because there's no actual file at that path. The solution is to route all requests to index.html so JS can handle the routing.