agentleFS
louisbrulenaudetlouisbrulenaudet/monorepo-template/.cursor/rules/frontend/tanstack-router.mdc

monorepo-template / frontend

Cursor rule18 starsChanged 59 days agoApache-2.0View on GitHub

TanStack Router - committed routeTree, routes/pages split, Query preload staleTime

The file

Files
tanstack-router.mdc
---
description: "TanStack Router - committed routeTree, routes/pages split, Query preload staleTime"
alwaysApply: false
globs: apps/front-*/src/routes/**,apps/front-*/src/pages/**,apps/front-*/src/routeTree.gen.ts,apps/front-*/src/**/*router*
---

# TanStack Router (v1)

Client-side routing only: ignore TanStack Start, SSR, and server functions. Depth: skill `tanstack-router`.

- File-based routing through the Vite plugin (`tanstackRouter` before `@vitejs/plugin-react`, [vite-config.mdc](vite-config.mdc)).
- `routeTree.gen.ts` is generated and **committed**: never hand-edit it (hook-enforced); regenerate with the app's `routes:generate` / `routes:check`. It is excluded from OXC.
- Register the router once (`declare module "@tanstack/react-router" { interface Register { router: typeof router } }`): one `router`, one `<RouterProvider>`, `defaultPreload: "intent"`, `scrollRestoration: true`.
- Three layers: eager `src/routes/<path>.tsx` (loaders, guards, `validateSearch`) → `src/routes/<path>.lazy.tsx` (UI) → `src/pages/<Page>.tsx`. Route files stay thin.
- Typed `<Link>` / `useNavigate()` only - no hand-built internal URLs. Search params: `validateSearch` with a Zod v4 schema passed directly (native support; never reintroduce `@tanstack/zod-adapter`), `.catch()` fallbacks to keep inference, `loaderDeps` when loaders depend on search.
- Auth and redirects in `beforeLoad`, not render; throw `notFound()` from loaders when appropriate.
- Query integration: `queryClient` on the root context; loaders call `queryClient.query({ ...opts, staleTime: "static" })`; components `useSuspenseQuery(opts)`. Set `defaultPreloadStaleTime: 0` so Query's `staleTime` owns freshness (a common misconfiguration).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.