···11----
22-description:
33-globs: src/routes/**/*.tsx
44-alwaysApply: false
55----
66-# TanStack Router: Do NOT Import createFileRoute
77-88-When working with TanStack Router route files in the [src/routes](mdc:src/routes) directory, **NEVER** import the `createFileRoute` function.
99-1010-## Why This Rule Exists
1111-1212-The `createFileRoute` function is automatically made available in each route file through TypeScript module declarations in [src/routeTree.gen.ts](mdc:src/routeTree.gen.ts). This file contains module augmentation that declares `createFileRoute` for each specific route:
1313-1414-```typescript
1515-declare module './routes/index' {
1616- const createFileRoute: CreateFileRoute<...>
1717-}
1818-declare module './routes/basic' {
1919- const createFileRoute: CreateFileRoute<...>
2020-}
2121-// ... and so on for each route
2222-```
2323-2424-## Correct Usage
2525-2626-✅ **DO THIS** - Use `createFileRoute` directly without importing:
2727-```tsx
2828-// src/routes/example.tsx
2929-export const Route = createFileRoute({
3030- component: RouteComponent,
3131-});
3232-3333-function RouteComponent() {
3434- // component logic
3535-}
3636-```
3737-3838-❌ **DON'T DO THIS** - Never import createFileRoute:
3939-```tsx
4040-// src/routes/example.tsx
4141-import { createFileRoute } from '@tanstack/react-router' // ❌ WRONG!
4242-4343-export const Route = createFileRoute({
4444- component: RouteComponent,
4545-});
4646-```
4747-4848-## Key Points
4949-5050-- `createFileRoute` is globally available in route files through module declarations
5151-- Each route file gets its own typed version of `createFileRoute` with proper type safety
5252-- Importing it manually will cause TypeScript conflicts and is unnecessary
5353-- This pattern is automatically maintained by TanStack Router's code generation
5454-
···5757 component: RouteComponent,
5858});
59596060+// And we have debounced preloading
6061function PreloadFilterSubmitContextProvider(props: {
6162 initialName: string;
6263 handleSubmit: (nameFilter: string) => void;
+2
src/routes/filters.tsx
···2727 name: v.optional(v.string(), ""),
2828});
29293030+// Now we add in filtering, this is the basic version that does no preloading
3031function FilterSubmitContextProvider(props: {
3132 initialName: string;
3233 handleSubmit: (nameFilter: string) => void;
···169170 )}
170171171172 <PaginationNav
173173+ prefetch="intent"
172174 prevOffset={data.prevOffset ?? undefined}
173175 nextOffset={data.nextOffset ?? undefined}
174176 to="/filters"
-1
src/routes/index.tsx
···11-;
21import { useState } from "react";
32import logo from "../logo.svg";
43
···2020 offset: v.optional(v.number(), 0),
2121});
22222323+// Barely better than basic
2424+// If the component tree is large, the speedup would actually be important
2325export const Route = createFileRoute({
2426 validateSearch: searchParamsSchema,
2527 loaderDeps: ({ search }) => ({
+1-1
src/util/pokemon.ts
···33import * as v from "valibot";
44import { DB } from "~/data/db";
5566-export const POKEMON_LIMIT = 25;
66+export const POKEMON_LIMIT = 10;
7788const PokemonListParamsSchema = v.object({
99 offset: v.optional(v.number()),