Skip to content

Bug: React Router shows blank page for unknown route

Error message

                No route matched the current URL
              

Quick summary

The user navigated to a URL that doesn't match any defined route, and no catch-all route exists.

Why this happens

  • No catch-all route (path="*") defined

  • Route path doesn't match the URL pattern

  • Typo in the route path

Minimal example

✗ Broken code
<Routes>
  <Route path="/" element={<Home />} />
  <Route path="/about" element={<About />} />
  {/* No catch-all! */}
</Routes>
✓ Fixed code
<Routes>
  <Route path="/" element={<Home />} />
  <Route path="/about" element={<About />} />
  <Route path="*" element={<NotFound />} />
</Routes>

The path="*" route matches any URL that doesn't match the defined routes, showing a 404 page instead of a blank screen.

How to diagnose

  • Check all defined routes and their paths

  • Verify the URL the user navigated to

  • Look for a catch-all route

How to fix

  • Add a catch-all route: <Route path="*" element={<NotFound />} />

  • Fix the route path to match the URL

  • Add a redirect for common misspellings

How to prevent

  • Always include a catch-all 404 route

  • Use route constants to avoid typos

Related Resources

Related Glossary

Related Lessons

← Back to language