Next.js 15
Rules
- Always use App Router (
app/directory), never Pages Router (pages/) - Server Components by default — only add
"use client"when needed (state, effects, browser APIs) - Use
generateMetadata()for dynamic metadata, not<Head> - Use Server Actions for mutations, not API routes for simple forms
- Use
next/imagewith properwidth/heightorfill— never raw<img> - Use
next/link— never raw<a>for internal navigation - Route handlers go in
app/api/[route]/route.ts— export named functions (GET,POST) - Layouts in
layout.tsx, loading states inloading.tsx, error boundaries inerror.tsx - Use
unstable_cacheorrevalidateTagfor ISR — not legacygetStaticProps/getServerSideProps - Environment variables:
NEXT_PUBLIC_prefix for client-side only
Avoid
getServerSideProps,getStaticProps,getStaticPaths— these are Pages Router_app.tsx,_document.tsx— these are Pages RouteruseRouterfromnext/router— usenext/navigationinsteadnext/head— usegenerateMetadataexport- Wrapping Server Components in
"use client"unnecessarily