add-route
Skill0 starsChanged 2 months agoMITView on GitHub
How to add or change a page/route in this repo using TanStack Router's file-based routing. Use when creating a new screen, nesting routes, adding route params, or wiring navigation links.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- NarekManukyan/flutter-mobx-kittheir own version, first seen Sep 17, 2026
- Bufferoverflovv/FastMCP-Blueprinttheir own version, first seen Apr 5, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- Bufferoverflovv/FastMCP-Blueprint★ 0same name
- NarekManukyan/flutter-mobx-kit★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- design-systemSkill
- react-patternsSkill
- testingSkill
- ui-designSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 0 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Every route file exports a Route created with createFileRoute, whose path string must match the filename.
- Very specific: line 76
Prefer search params over useState for filters, tabs and pagination — the view becomes shareable and survives reload.
- Very specific: line 81
Always use <Link>, never a bare <a href> for internal navigation — you lose client-side routing and prefetching.
- Very specific: line 110
Add a route-level errorComponent when a specific screen needs a more useful message than the generic one.
- Very specific: line 124
Create the file in src/routes/, named for the URL you want.
- Very specific: line 126
Run pnpm dev (or pnpm build) once so the tree regenerates.
- Very specific: line 127
Add it to NAV in __root.tsx if it should appear in the sidebar.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Adding a route
Routing is file-based via @tanstack/router-plugin, configured in
vite.config.ts. Files in src/routes/ generate src/routeTree.gen.ts.
Never edit routeTree.gen.ts
It is generated. The plugin rewrites it whenever pnpm dev or pnpm build
runs. It is excluded from linting and Prettier. Edits are lost silently.
File naming → URL
| File | URL |
src/routes/index.tsx | / |
src/routes/about.tsx | /about |
src/routes/users.index.tsx | /users |
src/routes/users.$userId.tsx | /users/:userId |
src/routes/settings.profile.tsx | /settings/profile |
src/routes/_auth.tsx | pathless layout (wraps children, adds no segment) |
src/routes/__root.tsx | the app shell — wraps everything |
The shape of a route file
Every route file exports a Route created with createFileRoute, whose path
string must match the filename. Get it wrong and the generator will correct
it on the next run.
import { createFileRoute } from '@tanstack/react-router'
function Settings() {
return <div>…</div>
}
export const Route = createFileRoute('/settings')({ component: Settings })Exporting Route alongside the component is the router's contract, which is
why react-refresh/only-export-components is switched off for
src/routes/** in eslint.config.js.
Params and search
Both are fully typed — that is the point of this router.
// src/routes/users.$userId.tsx
export const Route = createFileRoute('/users/$userId')({
component: User,
})
function User() {
const { userId } = Route.useParams() // typed as string
const { tab } = Route.useSearch() // typed by validateSearch
}Validate search params with Zod so bad URLs fail predictably:
export const Route = createFileRoute('/users')({
validateSearch: z.object({
page: z.coerce.number().default(1),
q: z.string().optional(),
}),
component: Users,
})Prefer search params over useState for filters, tabs and pagination — the
view becomes shareable and survives reload.
Linking
Always use <Link>, never a bare <a href> for internal navigation — you
lose client-side routing and prefetching.
<Link to="/users/$userId" params={{ userId: user.id }}>
Profile
</Link>A typo in to, or a missing param, is a type error at build time. If TS
complains about a to value, the route doesn't exist — create the file first
and let the tree regenerate.
Data loading
For server data, use TanStack Query inside the component (see the
react-patterns skill). Use the router's loader when the data must resolve
before the route renders — the loader receives context.queryClient, so it can
prefetch into the same cache the component reads:
loader: ({ context, params }) =>
context.queryClient.ensureQueryData(userQuery(params.userId)),Error and empty states
__root.tsx supplies an errorComponent and a notFoundComponent, so a
thrown error or an unknown URL renders a real page instead of a blank screen.
Add a route-level errorComponent when a specific screen needs a more useful
message than the generic one.
errorComponent receives error typed as unknown — anything can be
thrown. Narrow it with error instanceof Error rather than assuming.
Adding a page to the nav
src/routes/__root.tsx holds the NAV array that drives the sidebar. Add an
entry there; active state is derived from the router's current pathname, so
nothing else needs updating.
Checklist
- Create the file in
src/routes/, named for the URL you want. - Export
RouteviacreateFileRoutewith the matching path. - Run
pnpm dev(orpnpm build) once so the tree regenerates. - Add it to
NAVin__root.tsxif it should appear in the sidebar. pnpm check— a broken link or param shows up as a type error.
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
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.

