Rule
0 installs · 0 said it worked
Cursor rules for building React Router v7 apps correctly
A .mdc rule set guiding Cursor to structure React Router v7 routes, loaders, actions, navigation state, and tests in framework mode.
People use this for
- react router v7 framework mode
- react router loaders and actions
- react router route modules
- cursor rules react router
- building react router apps with progressive enhancement and typed loaders
- Name
cursor-rules-for-building-react-router-v7-apps-correctly- 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-building-react-router-v7-apps-correctly-5fq8/export/mdc" -o .cursor/rules/cursor-rules-for-building-react-router-v7-apps-correctly.mdcThen open a new session; Cursor picks it up from .cursor/rules/.
Manual install
Save cursor-rules-for-building-react-router-v7-apps-correctly.mdc as .cursor/rules/cursor-rules-for-building-react-router-v7-apps-correctly.mdc for this project or ~/.cursor/rules/cursor-rules-for-building-react-router-v7-apps-correctly.mdc for every project, then start a new session.
Rule
description: React Router v7 rules for framework mode, data routers, loaders, actions, route modules, and progressive enhancement globs: ["app/routes//*", "src/routes//", "routes/**/", "react-router.config.", "vite.config.", "/*.tsx", "/*.ts"] alwaysApply: false
React Router v7 Rules
Route Modules
- Use route modules as the boundary for route UI, loader data, actions, metadata, and error boundaries.
- Keep route modules small; move shared UI to components and reusable data access to services.
- Prefer file-based routing in framework mode when the project is configured for it.
- Use nested routes for shared layouts and progressive disclosure.
- Export route-specific
ErrorBoundarycomponents for recoverable route failures.
Data Loading
- Use loaders for route data that should be available before render.
- Keep loaders deterministic and side-effect free.
- Validate params and search params at the loader boundary.
- Return typed data and consume it through route hooks rather than duplicating fetch logic in components.
- Use deferred or streaming patterns only when they improve perceived performance.
Mutations
- Use actions for route mutations and form submissions.
- Prefer
Form,useFetcher, anduseSubmitfor progressive enhancement. - Revalidate affected loader data after mutations.
- Handle validation errors as typed action data instead of generic exceptions.
- Keep server-only secrets and privileged operations out of client actions.
Navigation and State
- Store shareable state in URL params or search params.
- Keep ephemeral UI state local to components.
- Use pending navigation state to show optimistic or loading UI.
- Avoid global state for data that belongs to route loaders.
TypeScript and Testing
- Type loader and action return values.
- Add tests for route loaders, actions, validation failures, and error boundaries.
- Use integration tests for critical form and navigation flows.
- Mock network and persistence at the route-service boundary.
Common Mistakes
- Do not duplicate loader fetches in
useEffect. - Do not mutate data in loaders.
- Do not hide route errors behind a single generic app-level catch-all.
- Do not put auth checks only in components when loader data is protected.
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
- Cursor rules for writing and testing Xian smart contracts in Python
A Cursor rules file that guides the assistant through writing Xian blockchain smart contracts in Python, covering naming, state, context variables, events, error handling, and unittest-based testing with security checks.
Coding · @patrickjs
- Quality engineering agent role for risk-based test strategy and CI quality gates
A senior quality engineering role prompt that guides an assistant through risk-based test strategy, test automation architecture, CI/CD quality gates, edge-case analysis, and defect management, writing results to a TODO checklist file.
Coding · @wkaandemir
- Security guardrails that keep an AI email assistant from being hijacked by malicious messages
A full system prompt giving an AI assistant that reads or manages email a security mindset: treat email as untrusted data, require approval for outward actions, avoid leaking private data, and report phishing and injection attempts calmly.
Productivity · @thanos0000
- 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
License: CC0v1 · published Nov 29, 2026
Comments
No comments yet. If you tried this prompt, say how it went.