404 errors on page refresh happen because your hosting platform tries to find a file matching the URL path (like /dashboard) instead of serving your SPA's index.html. The fix depends on your host: for Vercel, add a vercel.json with a rewrite rule. For Netlify, add a _redirects file in /public with /* /index.html 200. For lovable.app, this is handled automatically. The issue only occurs on external hosting platforms that do not know your app is a single-page application.
Why 404 errors appear on page refresh in Lovable single-page apps
Lovable builds single-page applications (SPAs) where React Router handles all navigation on the client side. When you click a link in your app to go from / to /dashboard, React Router updates the URL and swaps the page component without making a server request. This works perfectly. The problem occurs when the user refreshes the browser or navigates directly to a URL like /dashboard by typing it in the address bar. The browser sends a request to the hosting server asking for a /dashboard file. Since your app is a single HTML file (index.html) with JavaScript-based routing, there is no /dashboard file on the server. The server returns a 404 error. The solution is a server-side fallback rule that tells the hosting platform: 'If you cannot find a matching file, serve index.html instead.' Once index.html loads, React Router reads the URL, matches it to the correct route, and renders the right page. This is a hosting configuration issue, not a code issue — your React Router setup is likely correct, and the fix is a one-line configuration change on your hosting platform.
- No SPA fallback rule configured on the hosting platform — the server looks for files that do not exist
- The _redirects or vercel.json file was not included in the build output (placed outside /public or not committed to GitHub)
- Hosting platform auto-detected wrong framework settings and overrode the SPA configuration
- Using a static file server (like S3 or Nginx) without configuring a catch-all route to index.html
Error messages you might see
404 - Page Not FoundThe hosting server could not find a file at the requested URL path. This is expected for SPA routes — you need a fallback rule to serve index.html for all paths so React Router can handle the routing.
404 NOT_FOUND - The page could not be found (Vercel)Vercel's default error page when no file or rewrite matches the URL. Add a vercel.json file with a rewrite rule: { "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }.
Page Not Found - Looks like you've followed a broken link (Netlify)Netlify's default 404 page for unmatched routes. Add a _redirects file in the /public folder with the content: /* /index.html 200. This tells Netlify to serve index.html for all paths.
Before you start
- A Lovable project deployed to an external hosting platform (Vercel, Netlify, Cloudflare Pages, etc.)
- GitHub integration enabled (so configuration files sync to the hosting platform)
- The app works correctly in Lovable's preview panel — the 404 only occurs on the hosted version
How to fix it
Add a vercel.json rewrite rule for Vercel hosting
Vercel needs explicit rewrite rules to serve index.html for all SPA routes
Add a vercel.json rewrite rule for Vercel hosting
Vercel needs explicit rewrite rules to serve index.html for all SPA routes
Ask Lovable to create a vercel.json file in the project root (not inside /src or /public). This file tells Vercel to serve index.html for every URL path that does not match a real file. Once created, commit it to GitHub and Vercel will pick it up on the next deployment. You can also prompt Lovable: 'Create a vercel.json file in the project root with SPA rewrite rules so all routes serve index.html.'
// No vercel.json exists// Direct navigation to /dashboard returns Vercel's 404 page// vercel.json in project root{ "rewrites": [ { "source": "/(.*)", "destination": "/index.html" } ]}Expected result: Navigating directly to any route (like /dashboard or /settings) loads the app correctly instead of showing a 404 page.
Add a _redirects file for Netlify hosting
Netlify uses a _redirects file to configure SPA fallback routing
Add a _redirects file for Netlify hosting
Netlify uses a _redirects file to configure SPA fallback routing
Create a _redirects file inside the /public folder of your Lovable project. This file must be in /public so it gets copied to the dist/ build output. The file contains a single line that tells Netlify to serve index.html with a 200 status for all paths. Prompt Lovable: 'Create a file at public/_redirects with the content: /* /index.html 200.' Make sure the file has no file extension and is not named _redirects.txt.
// No _redirects file in /public// Direct navigation to /about returns Netlify's 404 page// public/_redirects (plain text file, no extension)/* /index.html 200Expected result: All routes resolve correctly on Netlify. Page refresh on any route loads the app and React Router renders the correct page.
Configure Cloudflare Pages or other static hosts
Each hosting platform has its own SPA fallback configuration method
Configure Cloudflare Pages or other static hosts
Each hosting platform has its own SPA fallback configuration method
For Cloudflare Pages, SPA mode is usually enabled by default, but you can verify it in your project's settings under Build Settings → Framework preset (set to None or Vite). For other static hosts, the approach varies: AWS S3 + CloudFront needs an error response configuration that returns index.html for 404s; Nginx needs a try_files directive; Apache needs a .htaccess rewrite rule. If configuring your specific hosting platform feels complex, RapidDev's engineers have deployed Lovable apps across every major hosting platform.
// Nginx default config — returns 404 for SPA routeslocation / { root /var/www/dist;}// Nginx with SPA fallback — serves index.html for all routeslocation / { root /var/www/dist; try_files $uri $uri/ /index.html;}Expected result: Your hosting platform serves index.html for all URL paths. React Router handles the routing from there.
Verify the fallback file is included in the build output
If the redirect file is not in the build output, the hosting platform never sees it
Verify the fallback file is included in the build output
If the redirect file is not in the build output, the hosting platform never sees it
After adding vercel.json (project root) or _redirects (/public), verify the file appears in the correct location. For vercel.json, it should be in the project root alongside package.json — Vercel reads it before building. For _redirects, it must be inside /public so Vite copies it to dist/ during build. Check in Dev Mode that the file exists and has the correct content. Then commit to GitHub and trigger a new deployment.
Expected result: The configuration file is present in the deployment. Test by navigating directly to a route URL — it should load your app instead of a 404 page.
Complete code example
1{2 "rewrites": [3 {4 "source": "/(.*)",5 "destination": "/index.html"6 }7 ],8 "headers": [9 {10 "source": "/assets/(.*)",11 "headers": [12 {13 "key": "Cache-Control",14 "value": "public, max-age=31536000, immutable"15 }16 ]17 },18 {19 "source": "/(.*)",20 "headers": [21 {22 "key": "X-Content-Type-Options",23 "value": "nosniff"24 }25 ]26 }27 ]28}Best practices to prevent this
- Add SPA fallback routing before your first deployment, not after — it prevents the most common hosting issue entirely
- Place _redirects in /public (not project root) so Vite copies it to the dist/ build output
- Place vercel.json in the project root (alongside package.json) where Vercel reads it before the build
- Test your deployment by navigating directly to a deep route URL (like /dashboard/settings) to confirm the fallback works
- Add a catch-all route in React Router (path="*") that renders a custom 404 component for routes your app does not handle
- If your app has both SPA routes and API endpoints, make sure the fallback rule does not override API routes
- After adding the configuration file, trigger a new deployment — most hosting platforms do not retroactively apply config changes
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
My Lovable (lovable.dev) app works perfectly in preview but shows 404 errors when I refresh the page on my hosted version. Hosting platform: [Vercel / Netlify / Cloudflare Pages / other] Framework: Vite + React + TypeScript + React Router Please: 1. Create the correct SPA fallback configuration file for my hosting platform 2. Tell me exactly where to place the file (project root vs /public) 3. Explain why this fixes the 404 issue 4. Include any caching headers that should be set alongside the rewrite
My deployed app shows 404 errors when users refresh the page or navigate directly to a URL like /dashboard. Please create the correct SPA fallback configuration: if I'm deploying to Vercel, create a vercel.json in the project root with a rewrite rule that sends all paths to /index.html. If Netlify, create a public/_redirects file with /* /index.html 200. Do not modify any React Router code — this is a hosting configuration fix.
Frequently asked questions
Why does my Lovable app show 404 when I refresh the page?
Your hosting platform looks for a file at the URL path (like /dashboard) but there is no such file — your app is a single-page application with only one HTML file. Add a fallback rule that serves index.html for all paths so React Router can handle the routing.
Does lovable.app have this 404 problem?
No. Lovable's built-in hosting at lovable.app automatically handles SPA routing. This issue only occurs on external hosting platforms like Vercel, Netlify, or self-hosted servers that need explicit SPA fallback configuration.
Where do I put the _redirects file for Netlify?
Place the _redirects file inside the /public folder of your Lovable project. Vite copies everything in /public to the dist/ build output during build. The file content should be a single line: /* /index.html 200.
Where do I put vercel.json for Vercel?
Place vercel.json in the project root directory, alongside package.json and vite.config.ts. Vercel reads this file before the build process. It should not be inside /public or /src.
Will the SPA fallback break my API routes?
If your Lovable project uses Supabase Edge Functions, API calls go to the Supabase domain, not your hosting platform, so the fallback will not interfere. If you have custom API routes on the hosting platform, add specific rules for those paths before the catch-all SPA rewrite.
My fallback file is in place but I still get 404s — what is wrong?
Trigger a new deployment after adding the configuration file — hosting platforms do not retroactively apply config changes to existing deployments. Also verify the file is in the correct location: vercel.json in project root, _redirects in /public.
What if I can't configure hosting myself?
Hosting configuration varies by platform and can involve SPA routing, environment variables, DNS, and SSL setup. RapidDev's engineers have deployed Lovable apps to every major hosting platform and can configure your hosting correctly.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation