PluginBench
Rule

react router v7

via PatrickJS/awesome-cursorrules

React Router v7 framework mode: route modules, data loaders, actions, and progressive enhancement patterns.

What is react router v7?

Establishes best practices for React Router v7 projects using framework mode, including route module organization, data loading with loaders, server mutations via actions, and progressive enhancement. Use this rule when building data-driven applications with file-based routing and form-centric workflows.

  • Organize route UI, loaders, actions, and error boundaries within route modules as the primary boundary
  • Load route data deterministically in loaders before render, validating params at the boundary
  • Handle mutations and form submissions through actions with typed validation errors and data revalidation
  • Store shareable state in URL params and keep ephemeral UI state local to components
  • Type loader and action return values; test loaders, actions, validation failures, and error boundaries

Applies to

File patterns this rule matches.

["app/routes/**/*"
src/routes/**/*
routes/**/*
react-router.config.*
vite.config.*
**/*.tsx
"**/*.ts"]
Rule definition (reference)

Source of truth, from the repository.

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 ErrorBoundary components 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, and useSubmit for 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.

Related rules

Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.

**/*
41k
via PatrickJS/awesome-cursorrules

Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.

**/*
41k
via PatrickJS/awesome-cursorrules

Android development with Jetpack Compose, clean architecture, and Material Design 3.

**/*
41k
via PatrickJS/awesome-cursorrules

Angular development with Novo Elements UI library using standalone components.

**/*
41k
via PatrickJS/awesome-cursorrules

Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.

**/*
41k
via PatrickJS/awesome-cursorrules

Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.

**/*.sh +5
41k
via PatrickJS/awesome-cursorrules