Capítulo 56 de 57

Chapter 56: Router API Reference

Core Idea

This page is the index of the entire public Router API surface, organized into Functions, Components, Hooks, Types, and a Deprecated section, serving as the map for looking up any specific TanStack Router API by category.

Key Concepts

  • Route-creation functions: createFileRoute, createLazyFileRoute, createRootRoute, createRootRouteWithContext, createRoute, createLazyRoute (creating routes eagerly, lazily, or with typed context), plus createRouteMask (URL masking) and createRouter (the main router instance factory).
  • Error/flow-control functions: redirect and isRedirect (throwable navigation), notFound and isNotFound (throwable missing-resource signaling), defer (deferred loader data).
  • Utility functions: getRouteApi (typed route accessor for code-split files), lazyRouteComponent, linkOptions (typed helper for building reusable link option objects), retainSearchParams and stripSearchParams (search param middleware helpers).
  • Core components: <Outlet> (nested route rendering), <Link> (navigation), <Navigate> (imperative redirect-as-component), <Await> (suspend on a deferred promise), <CatchBoundary> / <CatchNotFound> (error/not-found boundaries), <ErrorComponent>, <MatchRoute> (conditional rendering based on route match), <ClientOnly>, <DefaultGlobalNotFound>, <NotFoundComponent>.
  • Core hooks: useNavigate, useParams, useSearch, useLoaderData, useLoaderDeps, useRouteContext, useMatch, useMatches, useMatchRoute, useParentMatches, useChildMatches, useLocation, useRouter, useRouterState, useBlocker (navigation blocking/confirmation), useCanGoBack, useLinkProps, useAwaited (pairs with <Await>).
  • Key types: RouterOptions, RouterState, RouterEvents, RouteOptions, RouteMatch, RouteApi, LinkOptions/LinkProps, NavigateOptions, ToOptions, NotFoundError, Redirect, ParsedLocation, HistoryState, Register (the declaration-merging registration type), ViewTransitionOptions.
  • Deprecated classes: FileRoute, Route, Router, RouteApi, RootRoute, NotFoundRoute (class-based APIs), and rootRouteWithContext (superseded by createRootRouteWithContext) — all superseded by the modern factory-function equivalents.

Key Takeaways

  1. Use this page as a lookup index: functions for route/router construction and flow control, components for rendering concerns, hooks for reading router/route state, types for TypeScript signatures.
  2. Prefer the function-based APIs (createRoute, createRootRoute, etc.) over the deprecated class-based equivalents (Route, RootRoute, Router classes) which are being phased out.
  3. NotFoundRoute is explicitly deprecated in favor of notFoundComponent (see Ch 50); rootRouteWithContext function is deprecated in favor of createRootRouteWithContext.
  4. useBlocker, <MatchRoute>, and <Await>/useAwaited are notable hooks/components not covered in depth elsewhere in this doc set but worth knowing exist: useBlocker for navigation confirmation dialogs, <MatchRoute> for conditional UI based on whether a route matches, <Await>/useAwaited for consuming defer()-wrapped loader promises.

Connects To

  • Ch 44: Creating a Router, covers createRouter in depth.
  • Ch 49: Router Context, covers createRootRouteWithContext and the Register type in depth.
  • Ch 50: Not Found Errors, covers notFound/isNotFound/NotFoundError in depth.
  • Ch 57: File-Based Routing API Reference, the sibling reference page for file-based routing config rather than runtime router API.