Pages that break when you type their URL directly into the browser (instead of clicking a link within the app) are caused by the server not knowing about your app's routes. This is a Single Page Application (SPA) routing issue. Fix it by adding a fallback rule to your hosting platform that serves index.html for all paths, allowing your app's JavaScript to handle the routing.
Why typing a URL directly shows a 404 error in Lovable apps
Your Lovable app is a Single Page Application. That means the entire app is one HTML file (index.html) with JavaScript that swaps out content to show different 'pages'. When you click a link inside the app, the JavaScript handles it instantly — the browser never asks the server for a new page. But when you type a URL directly (like yourdomain.com/settings) or share that link with someone, the browser asks the server for a page called 'settings'. The server looks in its files, cannot find a folder or file called 'settings', and returns a 404 Not Found error. The fix is simple: tell the server to always return index.html no matter what URL is requested. Your app's JavaScript then reads the URL, sees '/settings', and shows the settings page. This is called a 'fallback rule' — the server 'falls back' to index.html for any path it does not recognize. This issue only affects deployed apps on external hosting platforms. Lovable's built-in hosting at lovable.app already handles this automatically.
- No fallback rule on the hosting platform — the server returns 404 for any path other than the root
- The app is deployed to an external host (Vercel, Netlify) without SPA configuration
- A user bookmarked or shared a deep link that the server cannot resolve directly
Error messages you might see
404 - Page Not Found (when typing a URL directly)The web server cannot find a file matching the requested URL. Your app is a Single Page Application that needs a fallback rule to serve index.html for all paths.
Cannot GET /settingsThe server is looking for a real file or folder at /settings. Since your app is a SPA, all routes are handled by JavaScript — the server just needs to serve index.html.
Before you start
- A Lovable project that works when navigating inside the app but breaks on direct URL access
- Knowledge of which hosting platform your app is deployed to
- Access to add files to your project via Dev Mode or GitHub
How to fix it
Identify that this is a SPA routing issue, not a code bug
Many users spend time debugging their code when the actual problem is a missing server configuration
Identify that this is a SPA routing issue, not a code bug
Many users spend time debugging their code when the actual problem is a missing server configuration
Test this simple check: go to your deployed app's home page (yourdomain.com). Click a link to navigate to another page (like Settings). Notice it works. Now refresh the browser on that page. If it shows 404, your code is fine — the server just needs a fallback rule. If the home page also shows 404, the issue is different (check that your build output is in the correct directory).
Expected result: You confirm the issue is a server-side fallback problem, not a JavaScript or React Router bug.
Add the fallback rule for your hosting platform
The fallback rule tells the server to serve index.html for any URL it does not recognize, letting your app handle the routing
Add the fallback rule for your hosting platform
The fallback rule tells the server to serve index.html for any URL it does not recognize, letting your app handle the routing
For Vercel: create a vercel.json file in your project root with a rewrite rule. For Netlify: create a _redirects file inside the /public folder. For Cloudflare Pages: the fallback is usually automatic for SPA frameworks, but you can add a _redirects file as well. Choose the file that matches your hosting platform. You only need one of these files.
1// For Vercel — create vercel.json in project root:2{3 "rewrites": [4 { "source": "/(.*)", "destination": "/index.html" }5 ]6}78// For Netlify — create /public/_redirects:9/* /index.html 200Expected result: All URLs serve your app's index.html. The browser loads your JavaScript, which reads the URL and shows the correct page.
Verify the fix by testing direct URL access
You need to confirm the fallback rule works before sharing links or telling your users the issue is fixed
Verify the fix by testing direct URL access
You need to confirm the fallback rule works before sharing links or telling your users the issue is fixed
After deploying with the fallback file, open a new incognito window. Type a deep URL directly into the address bar (like yourdomain.com/dashboard or yourdomain.com/settings/profile). The page should load correctly. Also test the browser's back and forward buttons, and try refreshing on every page. If any page still shows 404, check that the fallback file is in the correct location (vercel.json in the root, _redirects in /public). If the fix involves complex deployment configuration across multiple platforms, RapidDev's engineers can help.
Expected result: Every page in your app loads correctly whether accessed by clicking a link or typing the URL directly.
Complete code example
1# Netlify SPA fallback rule2# This tells Netlify to serve index.html for all paths3# that do not match a real file in the build output.4# The 200 status code means "serve this file as a success"5# (not a redirect). This is required for Single Page Apps.6#7# Place this file in the /public folder of your Lovable project.8# Vite copies everything in /public to the dist/ build output.910/* /index.html 2001112// Additional: Custom 404 page component13function NotFound() {14 return (15 <div className="flex flex-col items-center justify-center min-h-screen">16 <h1 className="text-4xl font-bold text-gray-900">404</h1>17 <p className="mt-2 text-gray-600">Page not found</p>18 <a href="/" className="mt-4 text-blue-600 hover:underline">19 Go back home20 </a>21 </div>22 );23}2425export default App;Best practices to prevent this
- Add the fallback file before your first deployment — do not wait for users to report broken links
- Place _redirects in /public (not the project root) so Vite includes it in the build output
- Place vercel.json in the project root (not /public) since Vercel reads it from the repository root
- Test direct URL access in an incognito window after every deployment to catch fallback issues early
- If sharing links to your app, always test the exact link in a private browser before sending it to others
- Lovable's built-in hosting at lovable.app handles SPA fallback automatically — this fix is only needed for external hosts
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
My Lovable.dev app shows a 404 error when I type a URL directly into the browser, but the page works fine when I click a link inside the app. - Hosting platform: [Vercel/Netlify/Cloudflare Pages/other] - Example URL that fails: [paste it] - Error message: [paste it] Please: 1. Confirm this is a SPA routing issue 2. Create the correct fallback configuration for my hosting platform 3. Tell me exactly where to place the file in my project 4. Explain how to verify it works after deployment
Create the files needed for SPA fallback routing on external hosting platforms. Add a vercel.json file in the project root with a rewrite rule that serves index.html for all paths. Also add a _redirects file in the /public folder for Netlify with the rule: /* /index.html 200. Do not modify any other files.
Frequently asked questions
Why does my page show 404 when I type the URL directly?
Your app is a Single Page Application where all pages are handled by JavaScript inside one index.html file. When you type a URL directly, the server looks for a matching file. Since it does not exist, it returns 404. Add a fallback rule so the server serves index.html for all paths.
Does this happen with all Lovable apps?
Only when deployed to external hosting platforms like Vercel, Netlify, or Cloudflare Pages. Lovable's built-in hosting at lovable.app handles this automatically. The issue appears because external hosts do not know your app is a SPA.
Do I need both vercel.json and _redirects?
No, you only need the file that matches your hosting platform. If deploying to Vercel, use vercel.json. If deploying to Netlify, use _redirects. Having both files does not cause problems, so you can include both for flexibility.
Will the fallback break if I also have an API on the same host?
If you have API routes on the same host, make sure the rewrite rule only applies to paths that do not match real files. Vercel's rewrites already do this by default. For Netlify, the _redirects rule respects existing files — it only applies when no matching file exists.
What if I can't fix this myself?
If your deployment involves custom server configurations, mixed routing with API endpoints, or multiple hosting platforms, RapidDev's engineers can configure the correct fallback routing for your specific setup.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation