setup-tanstack-router
/setup-tanstack-router
Auto-generate TanStack Router route tree and enforce router patterns via PostToolUse hooks. Bans react-router-dom, window.location, untyped hooks. Use when setting up TanStack Router or file-based routing.
- Author
- redpanda-data ↗
- Repository
- ui-harness ↗
- Licence
- MIT
- Last repository change
- 24.10.2026
Assessment and security
- Files in this package
- 5
- Scripts
- 3
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 24.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
- 3 scripts in this package. Review them before installing, as Claude may execute them.
Scripts: scripts/_hook-lib.sh, scripts/tanstack-router-check.sh, scripts/tanstack-router-gen.sh
What it does and when to use it
Auto-generate TanStack Router route tree and enforce router patterns via PostToolUse hooks. Bans react-router-dom, window.location, untyped hooks. Use when setting up TanStack Router or file-based routing.
Original author description
Auto-generate TanStack Router route tree and enforce router patterns via PostToolUse hooks. Bans react-router-dom, window.location, untyped hooks. Use when setting up TanStack Router or file-based routing.
How it works
- What This Catches
- TanStack Router + Query
- Customization
- Type-Safe Search Params with nuqs
SKILL.md preview
---
name: setup-tanstack-router
description: Auto-generate TanStack Router route tree and enforce router patterns via PostToolUse hooks. Bans react-router-dom, window.location, untyped hooks. Use when setting up TanStack Router or file-based routing.
paths:
- "**/routes/**/*.tsx"
- "**/routes/**/*.ts"
---
# TanStack Router Enforcement
## What This Catches
- Ban `react-router-dom` imports
- Ban `window.location` navigation (block) + reads (warn)
- Warn `window.location.reload()` -- suggest `router.invalidate()`
- Ban `strict: false` in router hooks
- Ban untyped `useParams()`/`useSearch()`/`useLoaderData()`/`useRouteContext()` missing `{ from }`
- Ban `URLSearchParams` -- suggest nuqs
- Warn exported components from route files (break code splitting)
- Require `validateSearch` when `useSearch` in route files
- Warn when Query-primed loaders are consumed via `useLoaderData` instead of `useQuery`/`useSuspenseQuery`
- Warn when router uses `queryClient` context without `defaultPreloadStaleTime: 0`
- Warn when router uses `queryClient` context without `createRootRouteWithContext`
Auto-regen route tree on route file change.
## TanStack Router + Query
When a route needs server data, prefer this ownership split:
- **Router loader**: start fetching early after navigation intent.
- **TanStack Query**: own cache, refetch, invalidation, and garbage collection.
- **Component**: read via `useQuery()` or `useSuspenseQuery()` so Query has an active observer.
Do **not** enforce suspense globally. Choose per field/page:
- `useSuspenseQuery()` for blocking, page-critical data that should use route pending/error boundaries.
- `useQuery()` for deferred or secondary data with inline loading/empty/error states.
```tsx
export const Route = createFileRoute('/dashboards/$dashboardId')({
loader: ({ context, params }) => {
context.queryClient.prefetchQuery(dashboardQueryOptions(params.dashboardId))
},
component: Dashboard,
})
function Dashboard() {
const params = Route.useParams()
const dashboard = useSuspenseQuery(dashboardQueryOptions(params.dashboardId))
const widgetCount = useQuery(widgetCountQueryOptions(params.dashboardId))
return <DashboardView dashboard={dashboard.data} widgetCount={widgetCount.data} />
}
```
Router setup when Query owns cache:
```tsx
const rootRoute = createRootRouteWithContext<{ queryClient: QueryClient }>()({
component: RootLayout,
})
const router = createRouter({
routeTree,
context: { queryClient },
defaultPreloadStaleTime: 0,
defaultPendingComponent: DefaultLoader,
defaultErrorComponent: DefaultError,
})
```
Avoid `Route.useLoaderData()` for Query-loaded data. It bypasses Query observers, so focus refetch, invalidation refetch, and cache retention can behave surprisingly.
## Customization
Routes dir pattern default `/routes/`. Update grep pattern in hook scripts if project use different convention:
```bash
if ! echo "$file_path" | grep -qE '/routes/'; then # default
if ! echo "$file_path" | grep -qE '/pages/'; then # pages-based
if ! echo "$file_path" | grep -qE '/app/routes/'; then # nested
```
## Type-Safe Search Params with nuqs
```tsx
import { useQueryState, parseAsInteger, parseAsString } from 'nuqs'
function UsersPage() {
const [page, setPage] = useQueryState('page', parseAsInteger.withDefault(1))
const [filter, setFilter] = useQueryState('filter', parseAsString)
}
```
Setup (install, config, verify): see [SETUP.md](SETUP.md).
Files in this package (5)
- SETUP.md 1 KB
- SKILL.md 3 KB
- scripts/_hook-lib.sh 1 KB
- scripts/tanstack-router-check.sh 8 KB
- scripts/tanstack-router-gen.sh 1 KB
Versions
The database has no other skills named setup-tanstack-router.
Database snapshot: 13.11.2026 · package version 0eae433dfad2 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100react-tanstack-router
Use when implementing routing in a React app (NOT Next.js) with TanStack Router — file-based routes, loaders, search params. - 100tanstack-router
TanStack Router for React with file-based routing. Covers route definitions, layouts, authentication guards, loaders, and type-safe navigation. USE WHEN: user mentions "TanStack Router", "file-based routing", "type-safe routing", "route loaders", "beforeLoad", asks about… - 90TanStack Router
Expert guidance for TanStack Router including file-based routing, type-safe navigation, route loaders, search params, nested routes, and lazy loading. Use this when building type-safe React applications with client-side routing. - 95tanstack-router-best-practices
TanStack Router best practices for type-safe routing, data loading, search params, and navigation. Activate when building React applications with complex routing needs. - 100tanstack-router
TanStack Router type-safe file-based routing for React. Use for SPAs, TanStack Query integration, Cloudflare Workers, or encountering devtools, type safety, loader, Vite bundling errors. - 96react-dev
This skill should be used when building React components with TypeScript, typing hooks, handling events, or when React TypeScript, React 19, Server Components are mentioned. Covers type-safe patterns for React 18-19 including generic components, proper event typing, and routing…