Menu

App shows 404 when you refresh a page after deploying? Add the rewrite to index.html
📰

App shows 404 when you refresh a page after deploying? Add the rewrite to index.html

DEV Community: react·Ahmed Hassan Yaseen·7 days ago
#f4oMbOCd
#devtoreact#devto#dev#vercel#host
Reading 0:00
15s threshold

Your app works when you click around, then you refresh /dashboard and get one of these:

404: NOT_FOUND Page not found Cannot GET /dashboard

Enter fullscreen mode

Exit fullscreen mode

A single-page app handles routes like /dashboard in the browser. On a refresh, the host looks for a file at that path, finds none, and returns a 404 before your app even loads. The fix is a rewrite on the host that serves index.html for app routes.

I see this a lot when a Lovable or Bolt app moves off the builder's hosting to Vercel or Netlify for the first time.

Why it happens

No rewrite on the host. Lovable's hosting handles this for you. The same Vite build on Vercel, Netlify or a storage bucket needs the rule added.

The rule sits in the wrong place. Netlify's _redirects file has to end up in the published folder, and vercel.json has to be at the project root.

It's a redirect, not a rewrite.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.