Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP1stack specificStack: Next.js App Router
nextjsredirectlayoutssr
Handle redirects in layout to avoid half-painted pages
Perform server-side redirect/validation logic in layout.tsx (runs before the page paints) rather than client-side, so users don't see a half-rendered page before redirecting.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | // page.tsx client component |
| 2 | useEffect(() => { router.replace(defaultTab); }, []); // page already painted |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | // layout.tsx (server) runs before page paint |
| 2 | if (!availableTabs.includes(tab)) return redirect(`/ticker/${fullName}/${defaultTab}`); |
Explanation (EN)
Objašnjenje (HR)