What are route groups in the App Router?

A route group is a folder wrapped in parentheses, such as app/(marketing), that organizes routes or shares a layout without adding a segment to the URL. app/(marketing)/pricing/page.tsx is served at /pricing.

Why use them

  • Organization: group routes by team, feature or section without changing URLs.
  • Different layouts at the same level: (shop) routes get a cart header, (auth) routes get a centered card, while both live at the top level of the URL.
  • Opting some routes into a layout: move only the routes that need a layout into a group with that layout.tsx.
  • Multiple root layouts: remove the top-level app/layout.tsx and give each group its own root layout with <html> and <body>. Useful when sections have completely different designs.
  • Scoped loading states: a loading.tsx inside a group applies only to routes in that group.

Rules and pitfalls

  • Two groups must not resolve to the same URL. (a)/about/page.tsx and (b)/about/page.tsx cause a build error.
  • Navigating between routes that use different root layouts triggers a full page load, because the whole document changes.
  • With multiple root layouts and no top-level page.tsx, define the home page inside one of the groups.
  • Group names are only for developers; they never appear in URLs, usePathname() or params.

Code example

tsx
1// app/
2// ├── (marketing)/
3// │ ├── layout.tsx marketing header + footer
4// │ ├── page.tsx -> /
5// │ └── pricing/page.tsx -> /pricing
6// ├── (shop)/
7// │ ├── layout.tsx header with cart
8// │ ├── loading.tsx applies only to shop routes
9// │ └── products/page.tsx -> /products
10// └── (auth)/
11// ├── layout.tsx centered card layout
12// └── login/page.tsx -> /login
13
14// app/(auth)/layout.tsx
15export default function AuthLayout({ children }: { children: React.ReactNode }) {
16 return (
17 <div className="grid min-h-screen place-items-center bg-slate-50">
18 <div className="w-full max-w-sm rounded-xl bg-white p-6 shadow">{children}</div>
19 </div>
20 );
21}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app