Lovable projects using React Router do not include a custom 404 page by default, so users who visit a non-existent URL see a blank screen or a generic error. Fix this by adding a catch-all route with path="*" in your route configuration that renders a styled NotFound component. Include helpful navigation links and a search suggestion to keep users engaged instead of bouncing.
Why Lovable apps show a blank page for unknown URLs
Lovable generates single-page applications (SPAs) with React Router for client-side navigation. When a user visits a URL that does not match any defined route, React Router has nothing to render, so the page goes blank. There is no built-in fallback page unless you explicitly create one. This is different from traditional websites where the server returns a 404 HTML page. In a Lovable SPA, the server always returns index.html (that is what SPA fallback routing does), and then React Router decides what to display based on the URL path. If no route matches, nothing renders. A blank page is worse than a proper 404 message because users assume the app is broken. A well-designed 404 page tells users the page does not exist, offers a link back to the home page, and optionally suggests related pages. This improves user experience and reduces bounce rates.
- No catch-all route (path="*") defined in your React Router configuration
- The catch-all route exists but renders an empty or broken component
- Routes are nested incorrectly so some paths fall outside the router's scope
- SPA fallback not configured on the hosting platform, causing server-level 404s instead of loading the app
Error messages you might see
No routes matched location "/some-page"React Router could not find a route definition matching the current URL path. This appears in the browser console and means you need a catch-all route with path="*" to handle unmatched URLs.
404 Not FoundIf you see this as a full-page server error (not a styled page), your hosting platform is not configured for SPA routing. The server needs to return index.html for all paths so React Router can handle routing client-side.
Cannot GET /some-pageThis is a server-side error that appears when you directly visit a URL and the host does not have SPA fallback configured. Add a rewrite rule so all paths serve index.html.
Before you start
- A Lovable project with React Router already set up (most Lovable projects include this by default)
- At least one working route in your app (like a home page)
- Access to the Lovable editor to modify route configuration and create a new component
How to fix it
Create a styled NotFound component
A dedicated 404 page tells users the URL is wrong and gives them a way to navigate back to working pages
Create a styled NotFound component
A dedicated 404 page tells users the URL is wrong and gives them a way to navigate back to working pages
Create a new file at src/pages/NotFound.tsx. This component should display a clear message that the page was not found, include a prominent button linking back to the home page, and optionally suggest popular pages. Use Tailwind classes and shadcn/ui components to match your app's design. Keep the tone friendly and helpful, not technical.
// No NotFound component existsimport { Link } from "react-router-dom";import { Button } from "@/components/ui/button";const NotFound = () => { return ( <div className="min-h-screen flex items-center justify-center bg-background"> <div className="text-center space-y-6 p-8"> <h1 className="text-6xl font-bold text-muted-foreground">404</h1> <h2 className="text-2xl font-semibold">Page not found</h2> <p className="text-muted-foreground max-w-md"> The page you are looking for does not exist or has been moved. </p> <Button asChild> <Link to="/">Back to Home</Link> </Button> </div> </div> );};export default NotFound;Expected result: A new NotFound.tsx file in src/pages/ with a styled 404 message and a home button.
Add a catch-all route to your router configuration
The path="*" route matches any URL that was not matched by earlier routes, serving as the fallback
Add a catch-all route to your router configuration
The path="*" route matches any URL that was not matched by earlier routes, serving as the fallback
Open your main routing file (usually src/App.tsx or src/routes.tsx). Find where your Route components are defined. Add a new Route with path="*" that renders your NotFound component. This route must be the last one inside your Routes block because React Router matches top to bottom and path="*" matches everything.
<Routes> <Route path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/dashboard" element={<Dashboard />} /></Routes>import NotFound from "@/pages/NotFound";<Routes> <Route path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/dashboard" element={<Dashboard />} /> {/* Catch-all route — must be last */} <Route path="*" element={<NotFound />} /></Routes>Expected result: Visiting any non-existent URL (like /xyz) now shows your custom 404 page instead of a blank screen.
Add redirect suggestions to the 404 page
Suggesting related pages helps users find what they were looking for instead of leaving your app
Add redirect suggestions to the 404 page
Suggesting related pages helps users find what they were looking for instead of leaving your app
Enhance your NotFound component with a list of commonly visited pages. This reduces bounce rate and helps users who mistyped a URL. You can also add a delayed redirect that automatically sends users to the home page after a few seconds, with a visible countdown. If your app has many pages and the redirect logic spans multiple components, this can get complex with generated code. RapidDev's engineers have implemented this exact pattern across 600+ Lovable projects and can set it up quickly.
<Button asChild> <Link to="/">Back to Home</Link></Button><div className="space-y-4"> <Button asChild> <Link to="/">Back to Home</Link> </Button> <div className="space-y-2"> <p className="text-sm text-muted-foreground">Or try one of these:</p> <div className="flex gap-2 justify-center"> <Button variant="outline" size="sm" asChild> <Link to="/dashboard">Dashboard</Link> </Button> <Button variant="outline" size="sm" asChild> <Link to="/about">About</Link> </Button> </div> </div></div>Expected result: The 404 page now shows a home button plus quick links to Dashboard and About pages.
Verify SPA fallback is configured on your hosting platform
Without server-side fallback, directly visiting a URL shows a server 404 instead of loading your React app
Verify SPA fallback is configured on your hosting platform
Without server-side fallback, directly visiting a URL shows a server 404 instead of loading your React app
If you are publishing on Lovable's built-in hosting (lovable.app), SPA fallback is already configured. If you deployed to Vercel, add a vercel.json file with a rewrite rule: {"rewrites": [{"source": "/(.*)", "destination": "/index.html"}]}. For Netlify, add a _redirects file in your /public folder containing: /* /index.html 200. This ensures the server always returns your app's HTML file, letting React Router handle the URL client-side.
// No SPA fallback configured on hosting platform// vercel.json (for Vercel deployments){ "rewrites": [ { "source": "/(.*)", "destination": "/index.html" } ]}// public/_redirects (for Netlify deployments)// Content: /* /index.html 200Expected result: Directly visiting any URL in the browser loads your React app, which then shows either the matching page or your custom 404.
Complete code example
1import { useEffect, useState } from "react";2import { Link, useNavigate } from "react-router-dom";3import { Button } from "@/components/ui/button";45const NotFound = () => {6 const navigate = useNavigate();7 const [countdown, setCountdown] = useState(15);89 // Auto-redirect to home after 15 seconds10 useEffect(() => {11 const timer = setInterval(() => {12 setCountdown((prev) => {13 if (prev <= 1) {14 clearInterval(timer);15 navigate("/");16 return 0;17 }18 return prev - 1;19 });20 }, 1000);2122 return () => clearInterval(timer);23 }, [navigate]);2425 return (26 <div className="min-h-screen flex items-center justify-center bg-background">27 <div className="text-center space-y-6 p-8 max-w-lg">28 <h1 className="text-7xl font-bold text-muted-foreground">404</h1>29 <h2 className="text-2xl font-semibold">Page not found</h2>30 <p className="text-muted-foreground">31 The page you are looking for does not exist or has been moved.32 Redirecting to home in {countdown} seconds.33 </p>34 <div className="flex flex-col sm:flex-row gap-3 justify-center">35 <Button asChild>36 <Link to="/">Back to Home</Link>37 </Button>38 <Button variant="outline" asChild>39 <Link to="/dashboard">Go to Dashboard</Link>40 </Button>41 </div>42 </div>43 </div>44 );45};4647export default NotFound;Best practices to prevent this
- Always place the catch-all route (path="*") as the last Route inside your Routes block so specific routes match first
- Use a friendly, non-technical tone on your 404 page — avoid showing stack traces or error codes to end users
- Include at least one navigation link (preferably to the home page) so users can recover without using the back button
- Match the 404 page design to your app's theme using the same Tailwind classes and shadcn/ui components
- Consider adding an auto-redirect with a visible countdown — it guides lost users back to a working page automatically
- Test the 404 page by visiting a random URL path in the Lovable preview to make sure it renders correctly
- If deploying outside lovable.app, always configure SPA fallback routing on your hosting platform
- Log 404 hits to analytics so you can identify broken links or common misspelled URLs
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a Lovable project using React Router and I need a custom 404 page. Here is my current routing setup: [paste your App.tsx or routing file here] Please: 1. Create a styled NotFound component using Tailwind CSS and shadcn/ui Button 2. Add a catch-all route (path="*") to my existing routes 3. Include a countdown timer that auto-redirects to home after 15 seconds 4. Add suggested page links on the 404 page 5. Make sure the catch-all route is positioned last in the Routes block
Create a custom 404 page for my app. Add a new file @src/pages/NotFound.tsx with a styled error page that shows a large 404 heading, a friendly message saying the page was not found, a Back to Home button, and links to the dashboard and about pages. Add a catch-all route with path="*" as the last route in @src/App.tsx that renders this NotFound component. Use shadcn/ui Button and Tailwind CSS. Include an auto-redirect countdown to home after 15 seconds.
Frequently asked questions
How do I add a 404 page to my Lovable project?
Create a NotFound component in src/pages/NotFound.tsx with your error message and navigation links. Then add a catch-all route with path="*" as the last Route in your routing file (usually App.tsx). This route renders whenever no other route matches the URL.
Why does my Lovable app show a blank page for non-existent URLs?
Lovable generates SPAs with React Router, which only renders components for defined routes. If a URL does not match any route and there is no catch-all route, React Router renders nothing. Adding a path="*" route fixes this by providing a fallback component.
Where should I place the catch-all route in React Router?
Always place the path="*" route as the very last Route inside your Routes block. React Router matches routes top to bottom, so the catch-all must come after all specific routes. If placed first, it would match every URL and no other route would ever render.
Can I add an auto-redirect on my Lovable 404 page?
Yes. Use useState for a countdown timer and useEffect with setInterval to decrement it every second. When it reaches zero, call navigate("/") to redirect to the home page. Display the countdown so users know they will be redirected.
Do I need to configure anything on my hosting platform for the 404 page to work?
If you publish on lovable.app, SPA fallback is automatic. For Vercel, add a vercel.json with rewrite rules. For Netlify, add a _redirects file in /public. Without this, the server returns its own 404 page before React Router can load.
What if I can't fix this myself?
If your routing setup is complex with nested routes, auth guards, or multiple layouts, RapidDev's engineers can help. They have configured custom 404 pages and routing for 600+ Lovable projects and can resolve the issue quickly.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation