thin-route-file
What a route file holds.
The rule
Agents read this text as written when they write and review code.
A route file holds route wiring and nothing else: the loader, beforeLoad guards, validateSearch, head, and the one Screen it renders, imported from its feature's screens/. Read params and search through the route's own hooks, Route.useParams() and Route.useSearch(), never the untyped ones.
A component written in the route file may only turn params into the screen's props. Markup, state, a fetch, and anything that deserves a test of its own belong in the screen.
A route file is named by its URL, so nobody searching for a name finds the code in it.
Examples
The agent flags code like the incorrect example and accepts code like the correct one. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.
Incorrect
import { useQuery } from '@tanstack/react-query';import { createFileRoute, useParams } from '@tanstack/react-router';import { issueDetailQueryOptions } from '../features/issues/queries/issueDetailQueryOptions.ts';// Incorrect: the screen lives in the route file — a fetch, a loading branch and// markup under a URL for a name — and reads its params through the untyped hook.const IssueDetailPage = () => {const { issueId } = useParams({ strict: false });const { data: issue, isLoading } = useQuery(issueDetailQueryOptions({ issueId: Number(issueId) }));if (isLoading || issue === undefined) {return <p>Loading…</p>;}return (<article><h1>{issue.title}</h1><p>{issue.summary}</p></article>);};export const Route = createFileRoute('/issues/$issueId')({ component: IssueDetailPage });
Correct
import { createFileRoute } from '@tanstack/react-router';import { IssueDetailScreen } from '../features/issues/screens/IssueDetailScreen.tsx';import { issueDetailQueryOptions } from '../features/issues/queries/issueDetailQueryOptions.ts';// Correct: the route prefetches, names the tab and hands typed params to one// screen. Everything with a test of its own lives in the screen.const IssueDetailRoute = () => {const { issueId } = Route.useParams();return <IssueDetailScreen issueId={Number(issueId)} />;};export const Route = createFileRoute('/issues/$issueId')({loader: ({ context, params }) => context.queryClient.ensureQueryData(issueDetailQueryOptions({ issueId: Number(params.issueId) })),head: ({ params }) => ({ meta: [{ title: `Issue ${params.issueId}` }] }),component: IssueDetailRoute,});
Configure
- Block
"blocking"Stops a run when a file the run changed breaks the rule. - AdviseDefault
"advisory"Reports it and hands it to the refactor agent. Never stops a run. - Off
"off"Not checked. Use it when your own linter already enforces the rule.
Add this to your lightsout.config.json, then change the value.
{"standards-rule-settings": {"thin-route-file": "advisory"}}