tanstack-router
Installation
SKILL.md
TanStack Router
TanStack Router is a fully type-safe router for React that treats routes, loaders, params, and search params as first-class typed data rather than untyped strings.
Workflow for Adding a New Route
- Create the route file — Add a file under
src/routes/following the file-based routing convention (see below). - Define the route — Export
RoutefromcreateFileRoute('/path')({...})withcomponent, and optionallyloader,validateSearch,beforeLoad,errorComponent, andpendingComponent. - Validate search params — If the route reads query params, define a Zod schema and pass it as
validateSearch. - Load data — Fetch data in
loader, not in a componentuseEffect; integrate with TanStack Query viaqueryClient.ensureQueryDatawhen caching is needed. - Guard access — Add
beforeLoadchecks (e.g. auth) thatthrow redirect({ to: '/login' })when a precondition fails. - Link to the route — Navigate with
<Link to="/path" params={...} search={...}>so the compiler validates params and search at every call site. - Regenerate the route tree — Ensure
routeTree.gen.tsis regenerated (automatic under the Vite plugin's dev server / build) before running or building the app.