alpha

Makes a coding assistant an expert in TanStack Router for React, covering file-based routes, typed params, search validation, loaders, auth guards and tests.
description: "Cursor rules for TanStack Router v1 with file-based routing, typed params, search validation, loaders, auth guards, and route preloading."
globs: */
alwaysApply: false
You are an expert in TanStack Router, React, TypeScript, and modern type-safe client-side routing.
createFileRoute or createRootRoute — never use plain objectsloader functions, not in component useEffect@tanstack/react-router with Vite and the @tanstack/router-vite-plugin for file-based routingrouteTree.gen.ts auto-generation — never manually edit this filesrc/routes/ directorysrc/routes/__root.tsxsrc/routes/index.tsx for the home/index routesrc/routes/
__root.tsx ← Root layout (wraps all routes)
index.tsx ← / route
about.tsx ← /about route
posts/
index.tsx ← /posts route
$postId.tsx ← /posts/:postId (dynamic segment)
_layout.tsx ← Layout route (no path segment)
_auth/
login.tsx ← /login (grouped under auth layout)
(admin)/
dashboard.tsx ← /dashboard (pathless group)
// src/routes/posts/$postId.tsx
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/posts/$postId')({
loader: async ({ params }) => {
return fetchPost(params.postId) // fully typed params
},
component: PostComponent,
})
function PostComponent() {
const post = Route.useLoaderData() // type-safe loader data
const { postId } = Route.useParams() // type-safe params
return <div>{post.title}</div>
}
z.object() from ZodvalidateSearch option on route definitionRoute.useSearch() — never read raw window.location.searchimport { z } from 'zod'
import { createFileRoute } from '@tanstack/react-router'
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,
})
function SearchPage() {
const { page, q } = Route.useSearch()
// ...
}
<Link> from @tanstack/react-router — never <a href> for internal navigationuseNavigate() for programmatic navigationparams and search to Link — the compiler will catch mistakesimport { Link, useNavigate } from '@tanstack/react-router'
// Declarative
<Link to="/posts/$postId" params={{ postId: '123' }}>View Post</Link>
// Programmatic
const navigate = useNavigate()
navigate({ to: '/posts/$postId', params: { postId: post.id } })
loader for data that must be available before render (no loading spinners for critical data)ensureQueryData inside loaders for cachingstaleTime on loaders to avoid redundant fetches during navigationexport const Route = createFileRoute('/posts')({
loader: ({ context: { queryClient } }) =>
queryClient.ensureQueryData(postsQueryOptions()),
component: PostsPage,
})
errorComponent on routes to handle loader or render errorsnotFoundComponent for 404 states within a route subtreependingComponent for showing skeletons/spinners during data loadingexport const Route = createFileRoute('/posts/$postId')({
loader: fetchPost,
errorComponent: ({ error }) => <ErrorBanner message={error.message} />,
pendingComponent: () => <PostSkeleton />,
notFoundComponent: () => <NotFound />,
component: PostDetail,
})
__root.tsx and pass it when creating the router// __root.tsx
import { createRootRouteWithContext } from '@tanstack/react-router'
interface RouterContext {
queryClient: QueryClient
auth: AuthState
}
export const Route = createRootRouteWithContext<RouterContext>()({
component: RootLayout,
})
// main.tsx
const router = createRouter({
routeTree,
context: { queryClient, auth },
})
beforeLoad for authentication checks — redirect to login if unauthenticatedexport const Route = createFileRoute('/_auth/dashboard')({
beforeLoad: ({ context }) => {
if (!context.auth.isAuthenticated) {
throw redirect({ to: '/login' })
}
},
component: Dashboard,
})
preload on <Link> to trigger loader prefetching on hover/focusdefaultPreload: 'intent' on the router for automatic preloadinggcTime and staleTime on loaders to tune cache behaviorReact.lazy for code splitting@tanstack/router-devtools and render <TanStackRouterDevtools /> in developmentcreateMemoryHistory and createRouter to create isolated router instances in tests<RouterProvider router={testRouter} />Public domain (CC0 1.0) · by awesome-cursorrules contributors · source · posted by @OpenSourceBuffGuy on promptparty.com


Sea turtle carrying floating film studio island
Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.
image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost
Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.
video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

Cozy Pixel Art Farm Island Village
Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.
image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape
Loading reviews…
Loading comments…