Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Build new routes on the current router, not the legacy one
Add new pages to the actively-maintained router (App Router), not the deprecated Pages Router.
Bad example
| 1 | // pages/watchlist/index.tsx (legacy Pages Router) |
| 2 | import type { GetServerSideProps } from 'next'; |
| 3 |
|
| 4 | export default function WatchlistPage({ data }) { |
| 5 | return <Watchlist data={data} />; |
| 6 | } |
| 7 |
|
| 8 | export const getServerSideProps: GetServerSideProps = async () => { |
| 9 | const data = await fetchData(); |
| 10 | return { props: { data } }; |
| 11 | }; |
Explanation (EN)
A brand-new page is added to the legacy Pages Router. That router gets no new framework features and is on a path to deprecation, so new code there accrues migration debt from day one.
Objašnjenje (HR)
Potpuno nova stranica dodaje se u zastarjeli Pages Router. Taj router ne dobiva nove značajke frameworka i na putu je prema ukidanju, pa novi kod tamo od prvog dana stvara dug za migraciju.
Good example
| 1 | // app/watchlist/page.tsx (current App Router) |
| 2 | export default async function WatchlistPage() { |
| 3 | const data = await fetchData(); |
| 4 | return <Watchlist data={data} />; |
| 5 | } |
Explanation (EN)
The new page is built on the current App Router, gaining access to the latest features (server components, streaming, etc.) and avoiding a forced migration later.
Objašnjenje (HR)
Nova stranica izgrađena je na aktualnom App Routeru, čime dobiva pristup najnovijim značajkama (server komponente, streaming itd.) i izbjegava prisilnu migraciju kasnije.
Notes (EN)
Existing legacy-router pages can stay until migrated, but stop adding new ones there. The same principle applies to any deprecated-but-still-supported framework API.
Bilješke (HR)
Postojeće stranice na starom routeru mogu ostati dok se ne migriraju, ali prestani dodavati nove tamo. Isti princip vrijedi za bilo koji zastarjeli, ali još uvijek podržani API frameworka.
Exceptions / Tradeoffs (EN)
API routes or other features that the current router does not yet support may legitimately remain on the legacy router until equivalent support exists.
Iznimke / Tradeoffi (HR)
API rute ili druge značajke koje aktualni router još ne podržava mogu opravdano ostati na starom routeru dok ne postoji ekvivalentna podrška.