router-core/not-found-and-errors

Implement 404 handling, error boundaries, and route masking in TanStack Router applications.

1.4k|34|Updated Mar 7, 2024
One-click install
npx skills add https://github.com/mehdibha/dotUI --skill router-core-not-found-and-errors-mehdibha
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: router-core/not-found-and-errors
Source: https://github.com/mehdibha/dotUI/tree/main/.claude/skills/tanstack-router-not-found-and-errors
Command: npx skills add https://github.com/mehdibha/dotUI --skill router-core-not-found-and-errors-mehdibha

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router.

What problem does it solve? Handling missing pages, failed data loads, and broken routes in TanStack Router apps requires knowing which APIs to use and which deprecated patterns to avoid, and mistakes like using NotFoundRoute or reading loader data in a notFoundComponent silently break error handling. ## Core Features & Use Cases - Not-Found Handling: Configure global 404s with notFoundComponent, throw notFound() from loaders for missing resources, and control bubbling with notFoundMode (fuzzy vs root). - Error Boundaries: Attach per-route errorComponent with retry via router.invalidate(), plus router-wide defaultErrorComponent fallbacks. - Route Masking: Display a different URL than the rendered route using the mask option on Link, useNavigate, or declarative createRouteMask with unmaskOnReload control. - Use Case: When building a photo gallery where /photos/123 loads a missing post, throw notFound() in the loader to render a contextual 404 while preserving the parent layout, and mask the modal route so the browser shows the clean photo URL. ## Quick Start Show me how to add a global 404 page and per-route error boundaries with retry to my TanStack Router app.

Frequently Asked Questions about router-core/not-found-and-errors

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a 404 page in TanStack Router?▼

Add a notFoundComponent to your root route to render a global 404 for unmatched URLs. You can also set defaultNotFoundComponent on createRouter as a router-wide fallback for any route without its own handler.

How to handle missing resources with notFound() in TanStack Router loaders?▼

Throw notFound() inside a loader or beforeLoad when a resource does not exist, and the nearest parent route with a notFoundComponent renders it. Pass a routeId option to target a specific parent route for handling.

Why is notFound() not working in TanStack Router?▼

The deprecated NotFoundRoute blocks notFound() and notFoundComponent from functioning, so remove it and use notFoundComponent instead. Also note that leaf routes without children cannot catch path-based not-found errors.

Can I use useLoaderData inside notFoundComponent?▼

No, useLoaderData may be undefined in notFoundComponent because the loader may not have completed. Use Route.useParams, Route.useSearch, or Route.useRouteContext instead, or forward partial data via the data option on notFound().

How do I retry a failed loader in TanStack Router error boundaries?▼

Call router.invalidate() from your errorComponent to re-run the loader, which also resets the error boundary automatically. Calling reset() alone clears the boundary without re-running the loader.

Does TanStack Router route masking survive page reloads or sharing?▼

Masking data is stored in location.state, so masked URLs are lost when shared or opened in a new tab. Masks survive local reloads by default unless you set unmaskOnReload on the mask, link, or router.