agentleFS
swapnil-saalswapnil-saal/agentic-react-starter/.claude/skills/add-route/SKILL.md

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

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. Bufferoverflovv/FastMCP-Blueprint★ 0same name
    2. 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.

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
  1. Very specific:

    Every route file exports a Route created with createFileRoute, whose path string must match the filename.

    line 30
  2. Very specific:

    Prefer search params over useState for filters, tabs and pagination — the view becomes shareable and survives reload.

    line 76
  3. Very specific:

    Always use <Link>, never a bare <a href> for internal navigation — you lose client-side routing and prefetching.

    line 81
  4. Very specific:

    Add a route-level errorComponent when a specific screen needs a more useful message than the generic one.

    line 110
  5. Very specific:

    Create the file in src/routes/, named for the URL you want.

    line 124
  6. Very specific:

    Run pnpm dev (or pnpm build) once so the tree regenerates.

    line 126
  7. Very specific:

    Add it to NAV in __root.tsx if it should appear in the sidebar.

    line 127

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

FileURL
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.tsxpathless layout (wraps children, adds no segment)
src/routes/__root.tsxthe 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

  1. Create the file in src/routes/, named for the URL you want.
  2. Export Route via createFileRoute with the matching path.
  3. Run pnpm dev (or pnpm build) once so the tree regenerates.
  4. Add it to NAV in __root.tsx if it should appear in the sidebar.
  5. pnpm check — a broken link or param shows up as a type error.

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.