tanstack-router-runtime-behavior-and-ssr
TanStack Router Runtime Behavior and SSR
Use this skill when the task is primarily about what happens after a route matches: loading, failure, recovery, navigation side effects, or Router SSR.
Scope
- pending, error, and not-found boundaries
- retry and recovery behavior
- scroll restoration and navigation blocking
- document head and script emission
- Router SSR and hydration guardrails
Routing cues
pendingComponent,errorComponent,notFoundComponent,router.invalidate(), scroll restoration, navigation blocking,head(),HeadContent,Scripts, or Router SSR -> use this skill- route trees, params,
Link,Navigate, or route masking -> usetanstack-router-route-trees-and-navigation validateSearch,loaderDeps,loader,beforeLoad, auth, route context, or preloading -> usetanstack-router-search-params-and-loaders- generated route trees, plugin config,
.lazy.tsx, or ESLint Router tooling -> usetanstack-router-file-based-routing-and-tooling
Workflow
- Read references/runtime-lifecycle-and-recovery.md first.
- If the task touches scroll restoration, head management, blocking, or Router SSR, read references/scroll-head-and-ssr.md.
- Treat pending, error, not-found, and retry paths as route-owned behavior, not app-global decoration.
- Keep TanStack Start concerns out unless the request explicitly moves beyond Router SSR into Start features.
Quick example
import { createRouter } from '@tanstack/react-router'
export const router = createRouter({
routeTree,
scrollRestoration: true,
defaultPendingComponent: () => <div>Loading...</div>,
defaultErrorComponent: ({ error }) => <div>{error.message}</div>,
defaultNotFoundComponent: () => <div>Not found</div>,
})
Guardrails
- The route lifecycle is ordered. Search parsing and
beforeLoadhappen beforeloader, and pending UI appears only after the configured threshold. - Retry loader-driven failures with
router.invalidate()instead of only resetting the nearest render boundary. - Not-found handling is its own route boundary system. Prefer
notFound()andnotFoundComponentover ad hoc 404 branches. - Scroll behavior is router-owned when enabled. Only opt out per navigation when the UX truly needs it.
- Head and script output belong to route configuration, rendered with
HeadContentandScripts. - Router SSR is not TanStack Start. Keep Start-only concepts like server functions, static prerendering, and ISR out of router-only fixes.
Canonical APIs
pendingComponenterrorComponentnotFoundComponentrouter.invalidateuseBlockeruseElementScrollRestorationHeadContentScripts
Maintenance
- Snapshot date: 2026-03-24
- Package snapshot:
@tanstack/react-router@1.168.3
References
More from dobroslavradosavljevic/skills
base-ui-typescript-surface
Use for Base UI namespace contracts, change event types, generic render types, and wrapper typing patterns.
4base-ui-basic-primitives
Use for simple primitives with low integration complexity (Avatar, Button, Meter, Progress, Scroll Area, Separator).
4base-ui-root-providers
Use for CSP Provider, Direction Provider, and useDirection when wiring Base UI at the app root or across portals.
4base-ui-menus-navigation-and-toast
Use for Menu, Context Menu, Menubar, Navigation Menu, Toolbar, Toast, and shared command-surface patterns such as detached triggers and menu payloads.
4base-ui-forms-and-validation
Use for Base UI Field/Form primitives, validation flows, form controls, and advanced Number Field, Slider, and RadioGroup behavior.
4base-ui-disclosure-and-tabs
Use for stateful visibility components (Accordion, Collapsible) and tab navigation semantics.
4