router-core/not-found-and-errors

Configure notFound() and errorComponent for TanStack Router routes.

14.9k|1.8k|Updated Jan 14, 2019
One-click install
npx skills add https://github.com/TanStack/router --skill router-core-not-found-and-errors
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/TanStack/router/tree/main/packages/router-core/skills/router-core/not-found-and-errors
Command: npx skills add https://github.com/TanStack/router --skill router-core-not-found-and-errors

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TanStack Router's not-found and error handling addresses how to render 404-style content, and manage per-route error boundaries, including notFound() and errorComponent configurations, to provide graceful degradation.

Core Features & Use Cases

  • Global 404: configure notFoundComponent on a root or parent route to render a default not found UI.
  • Per-route notFound: throw notFound() inside a loader to render a route-specific not-found boundary.
  • Error boundaries: assign errorComponent per route to display loader errors and allow retry via router.invalidate().
  • notFoundMode: control not-found propagation with fuzzy or root modes.
  • Safe data patterns: avoid rely on useLoaderData in notFoundComponent; use Route.useParams/useSearch or data option.

Quick Start

Implement notFound() in a loader when a resource is missing and configure a notFoundComponent to render a friendly message.

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 handle 404 not-found errors in TanStack Router loaders?

To handle 404 not-found errors in TanStack Router, throw the notFound() function inside your loader when a resource is missing, then configure a notFoundComponent on the route to render a friendly not-found UI boundary.

What is the difference between global and per-route not-found handling in TanStack Router?

Global not-found handling uses a notFoundComponent on the root route for default 404 UI, while per-route not-found handling throws notFound() inside specific loaders to trigger route-specific not-found boundaries.

How do I display loader errors using error boundaries in TanStack Router?

Assign an errorComponent to your route to display loader errors in TanStack Router. This error boundary catches loader failures and allows users to retry the request via router.invalidate().

Does TanStack Router support controlling not-found propagation across nested routes?

Yes, TanStack Router supports controlling not-found propagation across nested routes using the notFoundMode configuration, which offers fuzzy or root modes to manage how 404 boundaries propagate.

Why should I avoid useLoaderData in TanStack Router notFoundComponent?

You should avoid useLoaderData in notFoundComponent because it follows safe data patterns. Instead, use Route.useParams, useSearch, or the data option to safely access parameters without relying on potentially missing loader data.

Can I configure route masking for not-found pages in TanStack Router?

Yes, TanStack Router supports route masking alongside not-found and error handling, allowing you to mask route URLs while configuring notFoundComponent and errorComponent for graceful degradation.