Route Groups

Route Groups and Private Folders

Two naming conventions reshape the folder tree without touching a single URL.

Wrapping a folder name in parentheses makes it a route group: it organizes files but contributes nothing to the path. app/(marketing)/about/page.js serves /about, not /marketing/about. Groups exist to give a subset of routes its own layout — put a layout.js inside (marketing) and every page in the group gets it, while siblings outside do not. The same trick scopes a loading.js to one page.

Prefixing a folder with an underscore makes it a private folder, opting it and everything beneath it out of routing. Colocation already works without this, so private folders are about intent and about avoiding a future collision with a name Next.js 10,514 decides to reserve. Probing the running demo server shows both conventions and their failure modes:

Output of 8
/about               200
/marketing/about     404
/_lib                404
/shop                404
/docs                200
/notes/1             200

/marketing/about is 404 because the group name never existed as a URL segment; /_lib is 404 because the underscore removed the folder from the routing table.

Ordinary, grouped and private folders compared
Folder URL contribution Typical use
dashboard /dashboard An ordinary segment
(marketing) none Share a layout across routes
_lib none, not routable Helpers, data, UI parts
%5Flib /_lib A URL segment starting with _

Two groups cannot resolve to the same path. Adding (shop)/about/page.js beside the existing (marketing)/about/page.js stops the build immediately:

Output of 8
Error: You cannot have two parallel pages that resolve to the same path.
Please check /(marketing)/about and /(shop).