Skip to content
Back to skills

Tanstack Router Knowledge Patch

ASecurity

TanStack Router

  • 25 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added September 5, 2026
developmentreact

Works with

  • cli

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add Nevaberry/nevaberry-plugins --skill tanstack-router-knowledge-patch --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Tanstack Router Knowledge Patch?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Tanstack Router Knowledge Patch
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/nevaberry-tanstack-router-knowledge-patch/badge)](https://www.skillsdirectory.com/skills/nevaberry-tanstack-router-knowledge-patch)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tanstack-router-knowledge-patch
description: TanStack Router
version: "1.170.46"
license: MIT
metadata:
  author: Nevaberry
---


# TanStack Router Knowledge Patch

Load this skill when changing TanStack Router route definitions, navigation,
search validation, loaders, build tooling, or Router and Start SSR.
Use the topic references for complete guidance and examples.

## Reference index

| Reference | Topics |
| --- | --- |
| [Code splitting and tooling](references/code-splitting-and-tooling.md) | Lazy routes, loader splitting, virtual and physical routes, generation, bundlers, Fast Refresh, HMR, package skills and CLI |
| [Loaders and SSR](references/loaders-and-ssr.md) | Revalidation, loader caching and recovery, SSR entries, streaming, serialization, hydration, runtime assets, React Server Components |
| [Rewrites, masks, and blocking](references/rewrites-masks-and-blocking.md) | Public URLs, rewrite composition, masks, blockers, link updates and preloads, hash navigation, scroll restoration |
| [Search and matching](references/search-and-matching.md) | Removed state fields, subscriptions, matching precedence, path parameters, search validators and middleware, route errors |

## Removed match state fields

Router state no longer exposes `pendingMatches` or `cachedMatches`.
Remove reads of these fields from `useRouterState` selectors when upgrading.

## Automatic splitting and lazy routes

Automatic file-route splitting runs in the bundler plugin. In Vite, register
`tanstackRouter` before the React plugin.

```ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { tanstackRouter } from '@tanstack/router-plugin/vite'

export default defineConfig({
  plugins: [tanstackRouter({ autoCodeSplitting: true }), react()],
})
```

`createLazyFileRoute` accepts four options: `component`, `errorComponent`,
`pendingComponent`, and `notFoundComponent`. Keep route matching and
data-loading options in the critical route file.

Automatic splitting keeps loaders eager by default. To split `loader`, opt in
through the bundler plugin's automatic code-splitting options.

## Loader revalidation, caching, and recovery

For successful but stale match data, the default `'background'` mode keeps
rendering that data during revalidation. Set the loader object's
`staleReloadMode: 'blocking'` to wait for fresh data, or set
`defaultStaleReloadMode: 'blocking'` in `createRouter` for the router default.

```tsx
export const Route = createFileRoute('/posts')({
  loader: {
    handler: () => fetchPosts(),
    staleReloadMode: 'blocking',
  },
})
```

Set `gcTime: 0` with `shouldReload: false` to discard unloaded loader data and
load again on re-entry or a loader-key change. Preloaded matches still use
`preloadGcTime`, so the first navigation can reuse the preload without reloading.

Use `onError` for route-loading errors and `onCatch` for errors caught by the
router's `CatchBoundary`. In `errorComponent`, call `router.invalidate()` to
rerun loaders and reset the boundary after a load failure. The `reset()` prop
retries rendering the boundary's children.

## URL rewrites and public URLs

Set `rewrite.input` on `createRouter` to map incoming URLs before matching.
Set `rewrite.output` to map internal URLs when generating links and committing
navigation. Each optional callback receives `{ url: URL }` and can return a
mutated or new `URL`, a full URL string, or `undefined` to skip the rewrite.

`rewrite: composeRewrites([localeRewrite, legacyRewrite])` runs inputs left to
right and outputs right to left. The router strips its configured `basepath`
before custom inputs and adds it after custom outputs.

Read `location.publicHref` for the public URL used in sharing or canonical
links, and `location.href` for the internal URL. When an output rewrite changes
the origin, `<Link>` uses an ordinary anchor that triggers a full page load.

The custom `hydrate` callback runs before the initial client route match.
Use it to install request-specific URL rewrites before the client compares
its matches with the server's.

## Route masks and reloads

Declare a typed mask with `createRouteMask` and register it in `routeMasks`
to apply it whenever its `from` route ID matches. For an individual `<Link>`
or `navigate()` call, pass a typed navigation object as `mask`, with its own
destination, params, and search.

A local reload preserves the mask by default because it uses the same browser
history entry. A copied URL matches the visible path because mask state stays
in that entry.

Set `unmaskOnReload: true` to match the visible path on a local reload.
In increasing precedence, configure it on the router, the `createRouteMask`
configuration, or the individual `<Link>` or `navigate()` call.

## Navigation blocking

`shouldBlockFn` receives typed `current` and `next` locations. Checking
`fullPath` or `routeId` narrows a location to that route's params and validated
search fields.

`enableBeforeUnload` independently controls browser confirmation for reloads
and tab closures, even when `shouldBlockFn` allows in-app navigation.
It accepts a boolean or a predicate.

```tsx
useBlocker({
  shouldBlockFn: () => formIsDirty,
  enableBeforeUnload: () => formIsDirty,
})
```

The router awaits blockers in sequence during in-app navigation.
Canceling in one blocker skips the remaining blockers.

## Search validation and middleware

When `validateSearch` throws, the router calls the route's `onError` with
`error.routerCode` set to `'VALIDATE_SEARCH'` and renders its `errorComponent`.

With Zod v3, use `zodValidator` so navigation uses the schema's input type and
route reads use its output type. Pair `fallback()` with `.default()` to recover
from malformed values while keeping the field typed and optional in navigation.
With Zod v4, pass the schema directly to `validateSearch`; `.catch()` preserves
input inference.

`zodValidator({ schema, input: 'output', output: 'input' })` makes navigation
use the schema's output type and route reads use its input type.
Wrap an Effect schema with `Schema.standardSchemaV1` to expose its input and
output types to `validateSearch`.

A route's `search.middlewares` transforms generated link URLs for that route
and its descendants. These middleware functions also run during navigation,
after search validation. Their context uses the output type of `validateSearch`,
including validator-supplied defaults.

A downstream `stripSearchParams` can remove values carried forward by
`retainSearchParams`. With default `page: 1` and current `page: 3`, omitting
`page` lets retention keep `3` even if validation adds the default; explicitly
navigating with `page: 1` lets stripping remove the field from the URL.

## Matching precedence and parameter parsing

At a given segment, precedence is static text, required parameters (`$id`),
optional parameters (`{-$id}`), then wildcards (`$`). Overlapping routes follow
this priority across browsers. `params.priority` breaks ties between otherwise
equally ranked path candidates; segment precedence still applies.

Keep optional parameters that callers may omit within the first 32 segments
of the full route path. Beyond that depth, the matcher requires the segment.

Returning `false` from `params.parse` is experimental: it skips a candidate
during incoming path matching. Throwing surfaces the error on the selected
match. Typed links to a route template still resolve that exact route and use
`params.stringify` to generate the URL.

## Server rendering and serialization

Share a router factory between server and client. `createRequestHandler` takes
a Web `Request` and prepares a handler returning a promise for a Web `Response`.
The SSR setup uses server memory history and automatically transfers resolved
loader data to `RouterClient`.

Use `defaultStreamHandler` from `@tanstack/react-router/ssr/server` to stream
HTML and deferred loader data. To add server-side providers, pass your wrapped
`RouterServer` as `children` to `renderRouterToStream` or `renderRouterToString`.
The request handler supplies the current `request`, `responseHeaders`, and `router`.

SSR payload serialization supports `undefined`, `Date`, `Error`, and `FormData`
by default. `Map`, `Set`, and `BigInt` may require a custom serializer.

In React Server Component code, import `notFound` and `redirect` from
`@tanstack/react-router`. Its `react-server` condition supplies server-safe
implementations for use in server functions.

## Hash navigation and scroll restoration

Hash links still scroll to the anchor with `resetScroll={false}`. The anchor
takes precedence over stale window positions through destination invalidation;
hash navigation skips resets for elements configured in `scrollToTopSelectors`.

The router restores the window and configured scroll elements independently,
so it can reset an uncached target even when it restores another target.
It samples positions when leaving the route, capturing changes since the last
scroll event.

Files in this skill

  • SKILL.md8.9 KB
  • coverage.json1.1 KB
  • references/code-splitting-and-tooling.md4.3 KB
  • references/loaders-and-ssr.md5.1 KB
  • references/rewrites-masks-and-blocking.md3.7 KB
  • references/search-and-matching.md3.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.