PluginBench
Rule

react router v7

via PatrickJS/awesome-cursorrules

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

What is react router v7?

Guidance for structuring React Router v7 applications using framework mode, data routers, and route modules. Covers data loading with loaders, mutations with actions, URL-based state management, and progressive enhancement patterns. Use this rule when building or refactoring a React Router v7 app to follow modern best practices.

  • Establish route modules as boundaries for UI, loaders, actions, and error handling
  • Define loader patterns for deterministic data fetching before render and param validation
  • Structure actions for form submissions and mutations with revalidation and typed error handling
  • Manage navigation state and ephemeral UI state separately from route data
  • Provide TypeScript typing and testing patterns for loaders, actions, and error boundaries
  • Identify common mistakes like duplicate fetches, loader mutations, and missing auth checks

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

React development with Styled Components integration and best practices.

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

Zero-loading-spinner React SPA with TanStack Router v1 + TanStack Query v5 for type-safe URLs and cache-first data.

["src/routes/**/*" +3
41k
via PatrickJS/awesome-cursorrules

Zero-loading-spinner routing with TanStack Router v1 and Query v5 for type-safe React SPAs

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

Expert guidance for React, TypeScript, Next.js 14, and Web3 stack development with Wagmi and Viem.

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

Full-stack React, TypeScript, and Symfony development assistant with Docker expertise.

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

React and TypeScript state management guidance for Zustand stores, selectors, middleware, persistence, and testing.

**/*.ts +1
41k
via PatrickJS/awesome-cursorrules