02 / 03

List some use cases of route groups.

  1. 1

    Organizing routes into groups e.g. by site section, intent, or team. Organize routes without affecting the URL path

  2. 2

    Enabling nested layouts in the same route segment level: Even though routes inside (marketing) and (shop) share the same URL hierarchy, you can create a different layout for each group by adding a layout.js file inside their folders.

  3. 3

    Creating multiple nested layouts in the same segment, including multiple root layouts.

  4. 4

    Adding a layout to a subset of routes in a common segment.

Difficulty: 5/10
Topics: route groups, middleware, layout sharing

Scenario Questions

0-2 years experience
  1. 1

    We have a small Next.js app with pages/about and pages/contact. How would you use a route group to add a shared layout without changing the URLs?

  2. 2

    If you place a file inside a folder prefixed with parentheses, like (admin)/dashboard.tsx, what effect does that have on the generated route?

2-5 years experience
  1. 1

    Your team needs to protect all admin pages with authentication middleware, but you don't want '/admin' in the URL. How would you structure route groups to achieve this, and what are the trade‑offs?

  2. 2

    During a release, a new API version is added under pages/api/v2, but the old version must stay live. Explain how you would use route groups to keep the URLs clean and avoid breaking existing clients.

5-8 years experience
  1. 1

    At scale, you have multiple feature teams each owning a set of routes that share different middleware and layouts. How would you organize route groups to minimize coupling and support independent deployments?

  2. 2

    You notice that adding many nested route groups is increasing build times. What strategies would you employ to mitigate this while preserving the benefits of route groups?

8+ years experience
  1. 1

    Your organization is migrating a monolithic Next.js codebase to a micro‑frontend architecture. How would you leverage route groups to facilitate a gradual migration, and what long‑term maintenance considerations arise?

  2. 2

    When planning a multi‑region deployment, you need to serve different content variants (e.g., locale, AB test) without polluting the URL space. Discuss how route groups can be used in conjunction with edge middleware, and the architectural implications.

Follow-up Questions

  • Can you sketch the folder structure you would create for that use case?
  • What happens if you need a dynamic segment inside a route group?
  • How would you verify that the middleware is only running for the intended routes?