-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat: added TanStack Router React cursorrules #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||
| --- | ||||||
| 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"] | ||||||
|
||||||
| globs: ["src/routes/**/*", "src/routeTree.gen.ts", "app.config.ts"] | |
| globs: "{src/routes/**/*,src/routeTree.gen.ts,app.config.ts}" |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This route-tree example calls _auth/ a pathless group, but the auth-guard snippet below uses createFileRoute('/_auth/dashboard'). Align the docs so the directory naming and the route path examples reflect the same convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Verify that the two .mdc files are duplicates
echo "=== Comparing file sizes ==="
ls -lh rules-new/tanstack-router.mdc rules/tanstack-router-react-cursorrules-prompt-file/tanstack-router.mdc
echo -e "\n=== Computing checksums ==="
md5sum rules-new/tanstack-router.mdc rules/tanstack-router-react-cursorrules-prompt-file/tanstack-router.mdc
echo -e "\n=== Checking for differences ==="
diff rules-new/tanstack-router.mdc rules/tanstack-router-react-cursorrules-prompt-file/tanstack-router.mdc && echo "Files are identical" || echo "Files differ"Repository: PatrickJS/awesome-cursorrules
Length of output: 554
Remove duplicate file.
This file is an exact duplicate of rules/tanstack-router-react-cursorrules-prompt-file/tanstack-router.mdc. The rules-new/ directory doesn't follow the repository's established structure pattern of rules/[name]-cursorrules-prompt-file/.
Delete rules-new/tanstack-router.mdc and retain only the properly organized version.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@rules-new/tanstack-router.mdc` around lines 1 - 99, Delete the duplicate
tanstack-router.mdc file in the rules-new folder: remove the file whose content
begins "Type-safe routing with TanStack Router v1..." (the duplicate of the
canonical
rules/tanstack-router-react-cursorrules-prompt-file/tanstack-router.mdc), and
ensure no other references or imports point to this removed file so only the
canonical tanstack-router.mdc remains in the repository.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,170 @@ | ||||||
| You are an expert in TanStack Router, React, TypeScript, and modern type-safe client-side routing. | ||||||
|
|
||||||
| # TanStack Router + React Guidelines | ||||||
|
|
||||||
| ## Core Philosophy | ||||||
| - TanStack Router is 100% type-safe — leverage TypeScript generics for route params, search params, and loader data | ||||||
| - Prefer file-based routing for scalability; use code-based routing only for highly dynamic use cases | ||||||
| - Always define routes with `createFileRoute` or `createRootRoute` — never use plain objects | ||||||
| - Route data loading belongs in `loader` functions, not in component `useEffect` | ||||||
| - Search params are first-class citizens — define their schema with Zod or Valibot for validation and type inference | ||||||
|
|
||||||
| ## Project Setup | ||||||
| - Use `@tanstack/react-router` with Vite and the `@tanstack/router-vite-plugin` for file-based routing | ||||||
| - Enable `routeTree.gen.ts` auto-generation — never manually edit this file | ||||||
| - Structure routes under `src/routes/` directory | ||||||
| - Root layout goes in `src/routes/__root.tsx` | ||||||
| - Use `src/routes/index.tsx` for the home/index route | ||||||
|
|
||||||
| ## File-Based Route Conventions | ||||||
| ``` | ||||||
| src/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) | ||||||
|
||||||
| login.tsx ← /login (grouped under auth layout) | |
| login.tsx ← /_auth/login (under auth segment) |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This auth-guard example uses createFileRoute('/_auth/dashboard'), but earlier in the file _auth/ is presented as a grouping mechanism (e.g., login.tsx -> /login). Align the route path here with the file-based routing convention you intend (either include /_auth everywhere or make _auth pathless and remove it from the route path).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # TanStack Router + React Cursor Rules | ||
|
|
||
| Cursor rules for building type-safe React applications with TanStack Router v1, including file-based routing, type-safe search params, loaders, route context, auth guards, and integration with TanStack Query. | ||
|
|
||
| ## What's covered | ||
| - File-based routing conventions and directory structure | ||
| - Type-safe params and search param validation with Zod | ||
| - Loader-based data fetching (with TanStack Query integration) | ||
| - Navigation with `<Link>` and `useNavigate` | ||
| - Error, pending, and not-found components | ||
| - Router context for dependency injection | ||
| - Authentication guards with `beforeLoad` | ||
| - Code splitting and preloading strategies | ||
| - DevTools setup and testing patterns | ||
|
|
||
| ## Author | ||
| Created by [usm4nhafeez](https://github.com/usm4nhafeez) | ||
|
|
||
| Contributed to [awesome-cursorrules](https://github.com/PatrickJS/awesome-cursorrules) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||
| --- | ||||||
| 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"] | ||||||
|
||||||
| globs: ["src/routes/**/*", "src/routeTree.gen.ts", "app.config.ts"] | |
| globs: src/routes/**/*, src/routeTree.gen.ts, app.config.ts |
Copilot
AI
Apr 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file-based routing tree labels _auth/ as a “Pathless auth layout group”, but later examples use /_auth/... paths. Please clarify whether _auth is pathless or a literal path segment and make the directory comment + route paths consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reorder entries alphabetically within the State Management category.
The State Management section entries should be in alphabetical order. Currently, the order is Redux → MobX → React Query → TanStack Router. The correct alphabetical order should be: MobX → React Query → Redux → TanStack Router.
As per coding guidelines, "Maintain alphabetical order within each category in the README.md file."
📝 Proposed reordering
🧰 Tools
🪛 LanguageTool
[style] ~183-~183: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...t development with MobX integration. - [React (React Query)](./rules/react-query-curs...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
[style] ~184-~184: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...opment with React Query integration. - [React (TanStack Router)](./rules/tanstack-rou...
(ENGLISH_WORD_REPEAT_BEGINNING_RULE)
🤖 Prompt for AI Agents