{"success":true,"name":"design-the-next-js-layout-and-route-tree-before-building-pag","description":"Starting a new Next.js app or section and about to create page files","category":"ai-brimind","path":"ai-brimind/design-the-next-js-layout-and-route-tree-before-building-pag/SKILL.md","file":"SKILL.md","content":"---\nname: design-the-next-js-layout-and-route-tree-before-building-pag\ndescription: \"Starting a new Next.js app or section and about to create page files\"\n---\n\n# Design the Next.js Layout and Route Tree Before Building Pages\n\n## When to use\nProject is Next.js App Router, and you are about to create pages or folders without planning which UI is shared (layouts) and how routes are grouped.\n\n## Example request\ncopying the same navbar and sidebar into every page → they belong once in a layout.tsx that wraps all children. — Shared UI lives in layouts. | dashboard pages need auth and a sidebar, marketing pages do not → two route groups like (dashboard) and (marketing), each with its own layout. — Route groups separate worlds. | putting state in a layout expecting it to reset per page → layouts persist across navigation and do not re-render. — Layout persistence is by design. | a page needs a totally different shell (no navbar at all) → a route group with its own layout, not if-conditions inside one giant layout. — Split layouts instead of branching them.\n\n## Instructions\nAct like an architect who draws the folder tree on paper before creating a single file in a Next.js App Router project. Before building: 1) List all the pages/sections the feature needs, and mark which UI repeats across them (navbar, sidebar, footer, auth guard). Repeated UI is a candidate for a layout.tsx, written once, never copy-pasted per page. 2) Group routes by 'world': pages sharing the same shell and rules go in one route group like (dashboard); pages with a different shell go in another like (marketing) or (auth). Route groups with parentheses organize without changing the URL. 3) Remember what Next.js already gives you at each folder level before writing custom wrappers: layout.tsx for shared UI that persists, template.tsx if it must remount on navigation, loading.tsx and error.tsx per section, not-found.tsx. Custom wrapper components are only glue when a built-in file convention does not cover it. 4) Know the trap: layouts do NOT re-render on navigation between their children — never put per-page logic or per-page state there. 5) If you cannot say for a piece of UI whether it is shared or per-page, ask or sketch the screens first instead of guessing. Only create files once the tree is confirmed, and explain why each layout sits at its level (which routes share it and why), not just that the folders 'work'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #484\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}