Routing and navigation
Nest and organize routes
Build deeper URLs, use route groups without changing those URLs, and keep private implementation folders out of the route tree.
8 minute lesson
Nested folders map naturally to nested paths: app/notes/new/page.tsx produces /notes/new. This makes route structure visible in the filesystem.
A folder in parentheses, such as app/(marketing), is a route group and does not add a URL segment. A private folder prefixed with _ is excluded from routing. Use these conventions to organize layouts and colocated code, not to disguise an unnecessarily complex URL structure.
Route groups are useful when two sections need different layouts without adding organizational words to their URLs. Because the group name disappears, (marketing)/about/page.tsx and (company)/about/page.tsx still compete for /about; Next.js cannot publish both. Multiple root layouts also cause a full page load when navigation crosses between them.
Private folders are an explicit signal that a subtree is implementation detail. Ordinary colocated files are already non-routable, so use _components or _lib when the signal improves navigation—not as compulsory ceremony. Shared domain rules should still live outside a route when several route trees use them.
Create /about inside a (marketing) group and /notes/new inside the notes route. Add one private _components folder, then predict every public URL from the tree before opening the browser.
Lesson completed