Rule
0 installs · 0 said it worked
Cursor rules for type-safe TanStack Router v1 React routing
Cursor rule set guiding an assistant to build type-safe React routing with TanStack Router v1, covering file-based routes, loaders, Zod-validated search params, auth guards, and TanStack Query integration.
People use this for
- tanstack router react type-safe
- react routing typed search params
- file-based routing react loaders
- tanstack router zod search validation
- how do i set up auth guards in react router
- Name
cursor-rules-for-type-safe-tanstack-router-v1-react-routing- Works with
- Cursor
- License
- CC0(as observed at the source)
- Version
- v1 · updated Nov 29, 2026
Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.
Are you the author?Claim this profileRequest removal
Use this rule
$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/cursor-rules-for-type-safe-tanstack-router-v1-react-routing-xutp/export/mdc" -o .cursor/rules/cursor-rules-for-type-safe-tanstack-router-v1-react-routing.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save cursor-rules-for-type-safe-tanstack-router-v1-react-routing.mdc as .cursor/rules/cursor-rules-for-type-safe-tanstack-router-v1-react-routing.mdc for this project or ~/.cursor/rules/cursor-rules-for-type-safe-tanstack-router-v1-react-routing.mdc for every project, then start a new session.
Rule
description: "Type-safe routing with TanStack Router v1 for React apps, including file-based routing, loaders, search params validation, auth guards, and TanStack Query integration" globs: ["src/routes/**/*", "src/routeTree.gen.ts", "app.config.ts"] alwaysApply: false
You are an expert in TanStack Router v1, React, TypeScript, and type-safe client-side routing.
Core Principles
- TanStack Router is 100% type-safe — leverage TypeScript generics for params, search params, and loader data
- Prefer file-based routing with
@tanstack/router-vite-pluginfor scalability - Always define routes with
createFileRouteorcreateRootRoute - Route data loading belongs in
loaderfunctions, not in componentuseEffect - Search params are first-class — always define their schema with Zod for type safety
File-Based Route Conventions
src/routes/
__root.tsx ← Root layout
index.tsx ← / route
posts/
index.tsx ← /posts
$postId.tsx ← /posts/:postId (dynamic)
_layout.tsx ← Layout route (no path segment)
_auth/ ← Pathless auth layout group
dashboard.tsx
Route Definition
export const Route = createFileRoute('/posts/$postId')({
loader: async ({ params }) => fetchPost(params.postId),
component: PostComponent,
errorComponent: ({ error }) => <ErrorBanner message={error.message} />,
pendingComponent: () => <PostSkeleton />,
})
function PostComponent() {
const post = Route.useLoaderData() // type-safe
const { postId } = Route.useParams() // type-safe
return <div>{post.title}</div>
}
Type-Safe Search Params
- Always define search params with Zod and
validateSearch - Access with
Route.useSearch()— never readwindow.location.searchdirectly
const searchSchema = z.object({
page: z.number().int().min(1).default(1),
q: z.string().optional(),
})
export const Route = createFileRoute('/search')({
validateSearch: searchSchema,
component: SearchPage,
})
Navigation
- Use
<Link>for internal navigation — never<a href> - Always pass typed
paramsandsearch— the compiler will catch mistakes
<Link to="/posts/$postId" params={{ postId: '123' }}>View Post</Link>
Loaders + TanStack Query Integration
export const Route = createFileRoute('/posts')({
loader: ({ context: { queryClient } }) =>
queryClient.ensureQueryData(postsQueryOptions()),
component: PostsPage,
})
Router Context for Dependency Injection
// __root.tsx
interface RouterContext { queryClient: QueryClient; auth: AuthState }
export const Route = createRootRouteWithContext<RouterContext>()({ component: RootLayout })
// main.tsx
const router = createRouter({ routeTree, context: { queryClient, auth } })
Auth Guards
export const Route = createFileRoute('/_auth/dashboard')({
beforeLoad: ({ context }) => {
if (!context.auth.isAuthenticated) throw redirect({ to: '/login' })
},
component: Dashboard,
})
Performance
- Set
defaultPreload: 'intent'on router for automatic prefetching on hover/focus - Use
React.lazyfor route component code splitting - Install
@tanstack/router-devtoolsand render<TanStackRouterDevtools />in development
No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.
Tried it
Reports from people who added this rule to their editor. They roll up into the badges above.
No one has filed a report yet. Try the prompt and be the first.
Related rules
- Cursor rules for building type-safe TanStack Router apps in React
Cursor rules that guide the AI to write TanStack Router v1 code in React and TypeScript, covering file-based routing, typed params, Zod search validation, loaders, auth guards, and preloading.
Coding · @patrickjs
- Data validation architect role for multi-layer input validation and sanitization
A role prompt that turns the model into a senior data integrity expert who designs multi-layer input validation, sanitization, injection prevention, and error handling, and writes the plan to a TODO_data-validator.md checklist file.
Coding · @wkaandemir
- Cursor rules for type-safe React routing with TanStack Router and Query
Cursor rules guiding an AI assistant to build React single-page apps with TanStack Router for routing and TanStack Query for server state, using loaders to prefetch data and avoid loading spinners.
Coding · @patrickjs
- Agent role that turns TypeScript typing work into a tracked TODO plan
A senior TypeScript type-expert role prompt covering type design, generics, narrowing, and migration, with a required output of TODO_ts-type-expert.md containing checkable task items.
Coding · @wkaandemir
- Convex backend coding rules for Cursor AI assistant
A Cursor rules file (.mdc) that guides the AI to write Convex backend code with current best practices: new function syntax, validators, function registration, references, pagination, schema, and query and action rules.
Coding · @patrickjs
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.