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).
Keep page-specific headers and metadata out of global build config
Attach route-specific headers/metadata at the route level (layout/page), not in the global framework config, so config stays app-level and minimal.
Bad example
| 1 | // next.config.js |
| 2 | const nextConfig = { |
| 3 | async headers() { |
| 4 | return [ |
| 5 | { |
| 6 | source: '/product/:slug/app/:path*', |
| 7 | headers: [{ key: 'X-Robots-Tag', value: 'noindex' }], |
| 8 | }, |
| 9 | ]; |
| 10 | }, |
| 11 | }; |
Explanation (EN)
Routing/page-level header directives are buried in the global build config, which should stay focused on app-wide concerns. The directive lives far from the route it affects.
Objašnjenje (HR)
Direktive zaglavlja vezane uz pojedinu rutu zatrpane su u globalnoj build konfiguraciji, koja bi trebala ostati fokusirana na postavke razine aplikacije. Direktiva je daleko od rute na koju se odnosi.
Good example
| 1 | // app/product/[slug]/app/layout.tsx |
| 2 | export const metadata = { |
| 3 | robots: { index: false }, |
| 4 | }; |
| 5 |
|
| 6 | export default function AppViewLayout({ children }: { children: React.ReactNode }) { |
| 7 | return <>{children}</>; |
| 8 | } |
Explanation (EN)
The noindex directive is declared in the route subtree's layout, so it sits next to the pages it governs and the global build config stays minimal and app-level.
Objašnjenje (HR)
Noindex direktiva deklarirana je u layoutu podstabla rute, pa stoji uz stranice kojima upravlja, a globalna build konfiguracija ostaje minimalna i na razini aplikacije.
Notes (EN)
In Next.js App Router, route-subtree metadata (including robots directives) belongs in the segment's layout.tsx or page.tsx via the metadata export.
Bilješke (HR)
U Next.js App Routeru, metapodaci podstabla rute (ukljucujuci robots direktive) pripadaju u layout.tsx ili page.tsx segmenta putem metadata exporta.
Exceptions / Tradeoffs (EN)
If a header must apply across many unrelated routes or cannot be expressed at the page/layout level (e.g. truly cross-cutting security headers), the global config is the right place.
Iznimke / Tradeoffi (HR)
Ako se zaglavlje mora primijeniti na mnogo nepovezanih ruta ili se ne moze izraziti na razini stranice/layouta (npr. uistinu poprecna sigurnosna zaglavlja), globalna konfiguracija je pravo mjesto.