/lovable-issues

Creating and Customizing 404 Pages in Lovable

Learn why manually defined 404 pages in Lovable matter, how to add and customize yours, and best practices for effective error pages.

Book a free  consultation
4.9
Clutch rating 🌟
600+
Happy partners
17+
Countries served
190+
Team members
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

Why 404 Pages Must Be Manually Defined in Lovable

Lovable requires you to add a 404 page manually because it can’t safely infer or generate the correct framework-specific “not found” fallback for every project. Lovable’s preview and publish use your repository and build output as-is, and without a terminal/CLI it can’t run framework-specific build steps or make assumptions about routing, so the platform leaves the 404 decision to you to keep deployments deterministic and avoid breaking behavior.

 

Why this is the case

 

Deterministic builds: Lovable serves what’s in your repo/build output. Automatically inserting a 404 would change build artifacts in ways that might not match your framework’s expectations (Next.js, Remix, Astro, SvelteKit, plain static sites all handle 404s differently).

  • No terminal/CLI inside Lovable: Many frameworks need build-time commands or adapters to produce or wire up fallback pages. Lovable doesn’t run arbitrary shell commands in the editor environment, so it can’t perform those framework-specific steps reliably.
  • Routing and adapter differences: Some frameworks require a special file (public/404.html), others a pages/404.tsx file, others use serverless routing rules. Auto-guessing risks creating the wrong pattern and breaking client or server routing.
  • Determinism and safety: Explicit is safer — a manually defined 404 ensures your preview, tests, and production behavior match exactly what you expect, without side-effects from an automated “helpful” change.
  • When deeper control is needed: If you must run build scripts or add framework adapters, use GitHub sync/export and perform the changes locally or in CI; Lovable will preview/publish the resulting repo state.

 

// Create a documentation file that explains why 404 pages must be manual in this project.
// File to create: docs/WHY_404.md
// Place the exact text below into that file.

Explain why 404 pages must be manually defined in this project:

Lovable does not auto-generate framework-specific 404 pages because:
- The platform previews and publishes what exists in the repo/build output; automatically injecting a fallback can break framework routing or expectations.
- There is no terminal/CLI inside Lovable to run framework-specific build steps or adapters that some 404 implementations require.
- Different frameworks require different patterns (public/404.html, pages/404, special router configs); guessing would be unsafe.
- Requiring an explicit 404 keeps builds deterministic and avoids surprising production behavior.

If you need a framework-specific fallback that requires build-time work, use the GitHub sync/export workflow and run those steps outside Lovable.

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

How to Add and Customize a 404 Page in Lovable

In Lovable you add a 404 by creating the framework-appropriate file and wiring routing inside Chat Mode (no terminal). Paste one of the prompts below into Lovable's chat to have Lovable create the file(s) and update route(s). Then use Preview and Publish in Lovable. If your project needs a custom build step or adapter, use GitHub sync/export after the edits.

 

Next.js (recommended if your repo is Next)

 

Paste this prompt into Lovable chat to create pages/404.js and a small style; Lovable will add the file at pages/404.js.

  • Prompt for Lovable: Create a Next.js 404 page at pages/404.js with the exact code below. Do not change other files.
// Create pages/404.js
// This is a Next.js custom 404 page. Make it at pages/404.js.

import Link from 'next/link'

export default function Custom404() {
  return (
    <main style={{padding: '4rem', textAlign: 'center', fontFamily: 'system-ui, sans-serif'}}>
      <h1>404</h1>
      <p>We couldn't find that page.</p>
      <Link href="/"><a style={{color: '#0070f3'}}>Go home</a></Link>
    </main>
  )
}

 

React SPA using React Router

 

Paste this prompt into Lovable to create a NotFound component and update routing in src/App.jsx (or src/App.tsx). Tell Lovable exactly which file to modify.

  • Prompt for Lovable: Create src/pages/NotFound.jsx and update src/App.jsx to add a catch-all Route path="\*". Only edit the Routes block shown below.
// Create src/pages/NotFound.jsx
// Simple NotFound component

import { Link } from 'react-router-dom'

export default function NotFound() {
  return (
    <div style={{padding: '3rem', textAlign: 'center'}}>
      <h1>Page not found</h1>
      <p>The page you requested does not exist.</p>
      <Link to="/" style={{color: '#0366d6'}}>Return home</Link>
    </div>
  )
}
// Update src/App.jsx
// In the <Routes> block add the catch-all Route shown.

// existing imports...
import NotFound from './pages/NotFound'

// inside your <Routes> ... </Routes> component add:
<Route path="*" element={<NotFound />} />

 

Static site (plain HTML) — public/404.html

 

Paste this prompt into Lovable to add a static fallback at public/404.html. Useful for S3/GitHub Pages or static hosts.

  • Prompt for Lovable: Create public/404.html with the content below. Don't modify other files.
// Create public/404.html
// Static 404 page used by many static hosts

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>404 — Not Found</title>
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <style>
      /* simple inline styles */
      body { font-family: system-ui, sans-serif; display:flex; align-items:center; justify-content:center; height:100vh; margin:0; }
      .wrap { text-align:center; padding:1rem; }
      a { color:#0066ff; }
    </style>
  </head>
  <body>
    <div class="wrap">
      <h1>404</h1>
      <p>Oops — page not found</p>
      <a href="/">Go back home</a>
    </div>
  </body>
</html>

 

After Lovable makes the changes

 

  • Preview: Use Lovable's Preview to verify the new 404 page/route.
  • Publish: Click Publish in Lovable to deploy the changes via your configured deploy target.
  • If your deployment requires a build or adapter not supported inside Lovable, use GitHub sync/export from Lovable and run CI/build on your external host (this step is outside Lovable and requires a terminal or CI provider).

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Best Practices for Custom 404 Pages in Lovable

Custom 404 pages should be fast, accessible, discoverable by users and search engines, and work both as a server-side 404 (when the host returns 404) and as a client-side fallback (for SPA routing). Implement a tiny, focused 404 that includes a clear message, links back to useful places (home, search, sitemap), lightweight inline styling, a when the host can’t return a real 404 status, and a server/static fallback (public/404.html) so hosts that serve static files will return the right content. Test in Lovable’s Preview, then Publish or export to GitHub if you must add host-specific rewrite rules.

 

Content & design best practices

 

  • Keep it minimal and fast: inline very small CSS and avoid heavy JS so the page loads even when other assets fail.
  • Give useful navigation: include links to home, main categories, search or a sitemap — not just “go back”.
  • Brand consistently but sparingly: reuse header/footer HTML fragments if present, but avoid loading big component trees.
  • Communicate status: clearly state “404 — Page not found” and a short reason/action.

 

Accessibility & SEO best practices

 

  • Use semantic structure:
    , clear

    , descriptive text, and a focusable link back to the site.

  • Screen-reader friendly: ensure meaningful link text and skip links if your site uses them.
  • Handle indexing correctly: If your site or host will return a 200 for the SPA fallback, include on the 404 to avoid indexing incorrect content; if the host can return a real 404 status, prefer that for SEO.

 

Technical/hosting best practices (what to add in the repo)

 

  • Provide a static public/404.html so static hosts (Netlify, Vercel static mode) can return a server 404 when appropriate.
  • Provide a client-side fallback route (e.g., React Router Route path="\*" or Next.js pages/404.tsx) so SPA navigation shows the 404 when a route is unknown.
  • Add host rewrite/redirect config when needed only via GitHub export/sync — Lovable has no terminal. For Netlify, add public/\_redirects; for Vercel, add vercel.json. These require export to GitHub and then configuring the host.
  • Don’t load secrets or heavy API calls from the 404 page; keep it static. If you need dynamic suggestions (recent pages), fetch them client-side with a lightweight call and fall back gracefully.

 

Testing & deployment in Lovable

 

  • Use Preview to hit a non-existent route and confirm the client fallback renders and the static public/404.html loads when you open the root 404 file directly.
  • If you need host-level rewrites/redirects, use Lovable’s GitHub export/sync and configure the host (outside Lovable). Mark these changes in the repo so Lovable’s Publish remains consistent.
  • Keep it monitorable: add a lightweight client-side event (no secrets) that logs 404 counts to your analytics so you can detect frequent broken links.

 

Prompts to paste into Lovable (pick the one(s) that match your stack)

 

  • Static fallback (all static sites) — Paste this into Lovable chat to create public/404.html that is fast, accessible, and includes a noindex meta (safe if the host may return 200):
// Create file public/404.html with this content
// This is a minimal, fast static 404 intended for static hosts.
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="robots" content="noindex" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <title>404 — Page not found</title>
  <style>
    /* minimal inline styling */
    body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial;display:flex;min-height:100vh;align-items:center;justify-content:center;margin:0;padding:24px;background:#fff;color:#111}
    .box{max-width:720px;text-align:center}
    a{color:#0066cc}
  </style>
</head>
<body>
  <main class="box" role="main">
    <h1>404 — Page not found</h1>
    <p>We couldn't find the page you're looking for. Try returning to the <a href="/">homepage</a> or use the <a href="/sitemap.xml">sitemap</a>.</p>
  </main>
</body>
</html>

 

  • React Router fallback (create NotFound component + route) — Paste this to add src/components/NotFound.tsx and update src/App.tsx block to include a catch-all route. If your project uses TypeScript adjust file extensions accordingly.
// Create file src/components/NotFound.tsx with this content
import React from 'react';

export default function NotFound(){
  // small, self-contained component with minimal markup and styling
  return (
    <main style={{padding:24,display:'flex',flexDirection:'column',alignItems:'center'}}>
      <h1>404 — Page not found</h1>
      <p>Sorry — that route doesn't exist. <a href="/">Go to homepage</a></p>
    </main>
  );
}

// Update src/App.tsx in the <Routes> block to add:
// <Route path="*" element={<NotFound />} />
// (If you prefer a different file path or router setup, adjust accordingly.)

 

  • Next.js (if your site uses Next.js) — Paste this to create pages/404.tsx following Next.js conventions and including noindex meta if the host serves 200 for SPA fallback:
// Create file pages/404.tsx with this content
import Head from 'next/head';
import Link from 'next/link';
import React from 'react';

export default function Custom404(){
  return (
    <>
      <Head>
        <title>404 — Page not found</title>
        <meta name="robots" content="noindex" />
      </Head>
      <main style={{padding:24,maxWidth:800,margin:'0 auto'}}>
        <h1>404 — Page not found</h1>
        <p>We couldn't find that page. <Link href="/"><a>Return home</a></Link></p>
      </main>
    </>
  );
}

 

  • Netlify SPA rewrite helper (if you host on Netlify) — Paste to create public/\_redirects so that client-side routing still works; this file must be deployed via GitHub export/sync (outside Lovable):
// Create file public/_redirects with this content
/*    /index.html   200
// This allows SPA client-side routing to serve index.html for unknown paths.
// After adding this, export/sync to GitHub and deploy to Netlify (outside Lovable).

 

  • Testing & analytics note (add lightweight client log) — Paste to add a tiny, optional client-side analytics call you can use to count 404 hits without secrets. Create src/utils/log404.ts and import from the NotFound component:
// Create file src/utils/log404.ts
export function log404(){
  try{
    // lightweight fire-and-forget - no secrets or auth
    navigator.sendBeacon && navigator.sendBeacon('/_404log') || fetch('/_404log', {method:'POST',keepalive:true});
  }catch(e){}
}

// Then call log404() from your NotFound component's useEffect or on mount.
// The server endpoint /_404log can be a simple analytics collector if you have one.
// If you don't have a server endpoint, omit this step.

 

Final notes

 

  • Preview first: use Lovable Preview to visit an unknown route and open public/404.html directly — verify markup, links, and that the page is fast without heavy JS.
  • Use GitHub export/sync when you need host-specific files (like \_redirects or vercel.json) because Lovable can’t run host deployments or CLI commands directly.


Recognized by the best

Trusted by 600+ businesses globally

From startups to enterprises and everything in between, see for yourself our incredible impact.

RapidDev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with.

They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

Arkady
CPO, Praction
Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost.

He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Donald Muir
Co-Founder, Arc
RapidDev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space.

They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Mat Westergreen-Thorne
Co-CEO, Grantify
RapidDev is an excellent developer for custom-code solutions.

We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Emmanuel Brown
Co-Founder, Church Real Estate Marketplace
Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 

This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Samantha Fekete
Production Manager, Media Production Company
The pSEO strategy executed by RapidDev is clearly driving meaningful results.

Working with RapidDev has delivered measurable, year-over-year growth. Comparing the same period, clicks increased by 129%, impressions grew by 196%, and average position improved by 14.6%. Most importantly, qualified contact form submissions rose 350%, excluding spam.

Appreciation as well to Matt Graham for championing the collaboration!

Michael W. Hammond
Principal Owner, OCD Tech

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.