Skip to content
Back to skills

Tanstack Router Knowledge Patch

ASecurity

TanStack Router

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

Works with

  • cli

Security analysis

A100/100

Pro scans all 8 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-nevaberry-plugins/badge)](https://www.skillsdirectory.com/skills/nevaberry-tanstack-router-knowledge-patch-nevaberry-plugins)

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 compatibility guidance

Use this skill when working on TanStack Router route matching, navigation,
search validation, loaders, server rendering, or build tooling, including
the TanStack Start behaviors described in the references.
Choose the relevant topic below for full guidance and examples.

## Reference index

| Reference | Topics |
| --- | --- |
| [Code Splitting and Navigation](references/code-splitting-and-navigation.md) | Automatic splitting, lazy routes, blockers, link destinations, preloads, scroll restoration |
| [Loading and Server Rendering](references/loading-and-ssr.md) | Loader freshness, cache lifetime, errors, SSR entries, serialization, hydration, server component imports |
| [Matching and Parameters](references/matching-and-params.md) | Removed state fields, subscription observers, route precedence, optional depth, parameter parsing, path encoding |
| [Rewrites and Masking](references/rewrites-and-masking.md) | Input/output rewrites, composition, basepaths, public URLs, mask configuration and lifetime |
| [Search Parameters](references/search-params.md) | Validation errors, Zod and Effect adapters, middleware types, retention and stripping |
| [TanStack Start and Build Tooling](references/start-and-build-tooling.md) | Route generation, virtual routes, transforms, bundlers, HMR, deferred hydration, SSR assets, package skills |

## Remove obsolete match-state reads

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

## Keep candidate rejection experimental

Returning `false` from `params.parse` is an experimental way to skip 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.

Set `params.priority` to break ties between otherwise equally ranked path
candidates; segment precedence still applies. At a given segment, priority
runs from static text to required parameters (`$id`), optional parameters
(`{-$id}`), and wildcards (`$`).

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.

## Distinguish loading errors from render retries

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.

When `validateSearch` throws, the router calls the route's `onError` with
`error.routerCode` set to `'VALIDATE_SEARCH'` and renders `errorComponent`.
Error handling preserves primitive values thrown by `beforeLoad`.
Throwing `notFound()` during render reaches the route's `notFoundComponent`
without an explicit `routeId`.

## Configure automatic splitting in the bundler

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 file-route splitting keeps loaders eager by default. To split
`loader`, opt in through the bundler plugin's automatic code-splitting options.
Revisiting a code-split route reuses its resolved lazy component, avoiding the
pending UI caused by loading that component again.

## Control stale reloads and unloaded data

For successful but stale match data, the default `'background'` mode keeps
rendering that data during revalidation. Set `staleReloadMode: 'blocking'`
in the loader object 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.

## Map public URLs and configure masks

On `createRouter`, `rewrite.input` maps incoming URLs before route matching;
`rewrite.output` maps 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.

`composeRewrites([localeRewrite, legacyRewrite])` runs inputs left to right
and outputs right to left. The router strips `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. If an output rewrite changes
the origin, `<Link>` uses an ordinary anchor that triggers a full page load.

Register a typed `createRouteMask` result in `routeMasks` to apply it whenever
its `from` route ID matches. An individual `<Link>` or `navigate()` call can
take a typed navigation object as `mask`, with its own destination, params,
and search.

A local reload preserves the mask by default through 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.
Increasing precedence is router, `createRouteMask` configuration, then the
individual `<Link>` or `navigate()` call.

## Separate in-app and before-unload blocking

`shouldBlockFn` receives typed `current` and `next` locations. Checking
`fullPath` or `routeId` narrows a location to that route's params and validated
search fields. The router awaits blockers in sequence during in-app navigation;
canceling in one skips the remaining blockers.

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

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

## Preserve search input and output types

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.

```tsx
import { createFileRoute } from '@tanstack/react-router'
import { fallback, zodValidator } from '@tanstack/zod-adapter'
import { z } from 'zod'

export const Route = createFileRoute('/products')({
  validateSearch: zodValidator(
    z.object({ page: fallback(z.number(), 1).default(1) }),
  ),
})
```

With Zod v4, pass the schema directly to `validateSearch`; `.catch()` preserves
input inference. 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, and also runs during navigation after search validation.
The middleware context uses the output type of `validateSearch`, including
validator-supplied defaults. A downstream `stripSearchParams` can remove values
carried forward by `retainSearchParams`.

## Share SSR setup and preserve hydration order

Share a router factory between server and client. `createRequestHandler` takes
a Web `Request` and prepares a handler returning a promise for a Web `Response`.
SSR uses server memory history and transfers resolved loader data to
`RouterClient` automatically. Use `defaultStreamHandler` from
`@tanstack/react-router/ssr/server` to stream HTML and deferred loader data.

For server-side providers, pass a wrapped `RouterServer` as `children` to
`renderRouterToStream` or `renderRouterToString`; the request handler supplies
`request`, `responseHeaders`, and `router`. See the reference for entry examples
and the corresponding Solid modules.

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

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.

## Account for link and scroll behavior

In React Router 1.170.42, links in routes being left skip destination recomputation
while navigation is pending. Clicks and preloads follow the displayed `href`.
`buildLocation` resolves explicit `mask` options and configured `routeMasks`
from the same source location as the destination.

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 in `scrollToTopSelectors`.
Window and configured scroll elements restore independently. Positions are
sampled when leaving the route, capturing changes since the last scroll event.

## Consult build and Start details by topic

Dots and leading or trailing underscores stay literal in virtual route paths.
Physical filenames use bracket escapes, such as `[_]docs[_]/index.tsx`.
Virtual route config imports resolve using `tsconfig.json` path aliases via `jiti`.

The Start compiler can split deferred `Hydrate` boundaries on Vite and Rsbuild.
The boundaries can preload client chunks, preserve server-rendered fallback HTML,
and replay interaction-triggered events after hydration.

Router and Start packages provide agent skills and CLI entry points through
`@tanstack/intent`. Use package-qualified `intent load` IDs of the form
`@tanstack/<package>#<skill>` for skill references across installed packages.
The build-tooling reference includes the published React Router skill commands.

Files in this skill

  • SKILL.md8.2 KB
  • coverage.json1.1 KB
  • references/code-splitting-and-navigation.md3.2 KB
  • references/loading-and-ssr.md4.4 KB
  • references/matching-and-params.md1.6 KB
  • references/rewrites-and-masking.md2.9 KB
  • references/search-params.md2.2 KB
  • references/start-and-build-tooling.md2.7 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.