c/frontend › command
0votes

Cursor rules for Next.js App Router

TemplateLow risk
submitted by u/client to c/frontend · 0 copies

A .cursor/rules/nextjs.mdc file for server components, data fetching, routing and caching done right.

Template · 2 variables
---
description: Next.js App Router conventions
globs: ["app/**/*.tsx","app/**/*.ts","src/app/**"]
alwaysApply: false
---

# Next.js App Router

- Server Components by default. Add "use client" only for state, effects, browser APIs or event handlers, and keep client components small and at the leaves.
- Fetch data in Server Components or route handlers, never with useEffect for initial data.
- `params` and `searchParams` are async: `const { slug } = await params`.
- Use `generateMetadata` for titles/descriptions on every page; set `alternates.canonical`.
- Mutations: Server Actions or route handlers in `app/api`; validate input with {{validation_library}}.
- Images via next/image with width/height; fonts via next/font.
- Use `loading.tsx`, `error.tsx` and `not-found.tsx` instead of ad-hoc spinners and checks.
- Never import server-only modules (database clients, secrets) into client components.

## When you change code
- Follow the patterns in the nearest existing file before inventing new ones.
- Add or update a test for behavior changes; run `{{test_command}}`.
- Keep diffs small; explain anything surprising in your reply.
0 commentsreport

How to use this command

  1. Fill in the blanks. Type your details into the boxes above. This command has 2 blanks:
    • {{validation_library}} Validation library
    • {{test_command}} Test command
  2. Copy itwith the Copy button. Your answers are filled in automatically. Use “copy raw” to keep the blanks for later.
  3. Paste it into Cursor, Claude, ChatGPT or Codex and send it.
  4. Tip: This produces a file or document. Save the filled-in result in your project (for example as CLAUDE.md or AGENTS.md) so you can reuse it.

More from c/frontend

See all of c/frontend →
0 comments

Log in to join the discussion.