setup-tanstack-router
Setup TanStack Router
What This Sets Up
generate:routespackage.json script- PostToolUse hook (Write/Edit) that regenerates route tree when route files change
- PostToolUse hook (Write/Edit) that catches routing anti-patterns:
- Ban
react-router-domimports - Ban
window.locationfor navigation (block) and reads (warn) - Warn on
window.location.reload()— suggestrouter.invalidate() - Ban
strict: falsein router hooks - Ban untyped
useParams(),useSearch(),useLoaderData(),useRouteContext()without{ from } - Ban
URLSearchParams— suggest nuqs - Warn on exported components from route files (breaks code splitting)
- Require
validateSearchwhenuseSearchis used in route files
- Ban
Steps
1. Add package.json script
{
"scripts": {
"generate:routes": "tsr generate"
}
}
2. Create hook scripts
Copy scripts/tanstack-router-gen.sh, scripts/tanstack-router-check.sh, and scripts/_hook-lib.sh into .claude/hooks/. Make all executable.
During setup, ask the user for their routes directory path (default: src/routes/).
3. Configure hooks in .claude/settings.json
Add to hooks config: PostToolUse (matcher: Edit|Write):
.claude/hooks/tanstack-router-gen.sh.claude/hooks/tanstack-router-check.sh
4. Verify
-
bun run generate:routesworks - Creating a new route file triggers regeneration
- Hook blocks
react-router-domimports - Hook blocks
window.location.href = ... - Hook warns on
window.location.reload() - Hook blocks
strict: false - Hook blocks
useParams()without{ from } - Hook allows
Route.useParams() - Hook blocks
new URLSearchParams - Hook warns on exported components from route files
- Hook blocks
useSearchwithoutvalidateSearchin route files
5. TanStack official skills (optional)
For additional soft guidance (search params, data loading, auth guards, error handling, type safety), install the official TanStack Router skills:
npx @tanstack/intent@latest install
This adds 28 reference skills from the TanStack Router docs. They complement the hooks above with patterns and examples that are too context-dependent to enforce deterministically.
6. Commit
Stage and commit: Add TanStack Router auto-generation and anti-pattern hooks
More from malinskibeniamin/skills
setup-react-rules
Enforce React/TS/security rules via PostToolUse hooks — bans raw HTML, TS escape hatches, XSS vectors, barrel imports, missing passive listeners. Use when enforcing React patterns or component library standards.
9setup-react-compiler
Install React Compiler with rsbuild and enforce compiler-friendly patterns via PostToolUse hooks. Flags manual memoization, derived state, useRef cache. Use when setting up React Compiler or post-compiler patterns.
9setup-biome
Install Biome linter with Ultracite preset, create biome.jsonc config, and configure Claude Code Stop hook for auto-fix before finishing. Use when setting up linting, formatting, Biome, Ultracite, or code quality enforcement.
9setup-quality-gate
Add quality:gate package.json script for fast local/CI quality checks (biome + tsgo + related tests), GitHub Actions workflow, and Stop hook for type checking. Use when setting up quality gates, CI pipelines, or pre-push validation.
9setup-connect-query
Enforce ConnectRPC + Connect Query + Protobuf v2 patterns via PostToolUse hooks. Bans raw useQuery, empty invalidateQueries, $typeName literals. Use when setting up ConnectRPC, protobuf type safety, or data fetching enforcement.
8work-automation-kit
Install planning and project management skills — PRD creation, implementation planning, issue breakdown, bug triage, code review. Use when setting up project planning workflows or creating PRDs.
8