Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🔵 App Router – Pages, Layouts & Navigation  ·  Lesson 13

Route Groups & Private Folders

Why organise routes?

A real website has three kinds of pages: public marketing pages, login/register pages and an admin panel. Each needs a different look, but you do not want /marketing/about in the URL. Route groups solve this.

Route groups: (folder)

Wrap a folder name in parentheses. Next.js uses it for organisation and layouts, but skips it in the URL.

📁 app/
  📁 (marketing)/              # group – not in URL
    layout.jsx              # big header + footer
    page.jsx                # /
    about/page.jsx          # /about
    courses/page.jsx        # /courses
  📁 (auth)/
    layout.jsx              # small centered card, no menu
    login/page.jsx          # /login
    register/page.jsx       # /register
  📁 (admin)/
    layout.jsx              # sidebar dashboard
    admin/page.jsx          # /admin
    admin/students/page.jsx # /admin/students
  📁 _lib/                     # private – never a route
    format.js
  layout.jsx                # root layout (html, body)
Three groups, three layouts — URLs stay short
FileURL
app/(marketing)/about/page.jsx/about
app/(auth)/login/page.jsx/login
app/(admin)/admin/students/page.jsx/admin/students

Different layouts per group

JSX – app/(auth)/layout.jsx + login page
// app/(auth)/layout.jsx — login & register pages share this
export default function AuthLayout({ children }) {
  return (
    <div style={{ minHeight: '100vh', display: 'grid', placeItems: 'center', background: '#eef2ff' }}>
      <div style={{ width: 360, background: '#fff', padding: 28, borderRadius: 16 }}>
        <h2>EduSite</h2>
        {children}
      </div>
    </div>
  )
}

// app/(auth)/login/page.jsx  →  URL is /login (not /(auth)/login)
export default function Login() {
  return (
    <form>
      <input placeholder="Email" />
      <input type="password" placeholder="Password" />
      <button>Login</button>
    </form>
  )
}

(marketing) pages

  • Full header with menu
  • Footer with links
  • Wide content

(auth) pages

  • No menu (less distraction)
  • Centered card
  • Same root
Each group gets its own layout

Private folders: _folder

A folder starting with an underscore, like _lib or _components, and everything in it is never a route, even if it contains a page.jsx. Use it for helper files you want inside app/.

Colocation: keeping files together

Only page.jsx (and route.js) make a folder publicly visible. So a component used by one page can live right next to it:

Folder structure
app/
  courses/
    page.jsx            # the route
    CourseSearch.jsx    # used only by this page – not a route
    courses.module.css  # styles for this page
    [slug]/page.jsx
page.jsxpublic URLComponent.jsxnot publicstyle.module.cssnot public
Only special files create routes

The @/ import alias

JSON + JS – jsconfig.json
// jsconfig.json (created by create-next-app)
{
  "compilerOptions": {
    "paths": { "@/*": ["./*"] }
  }
}

// anywhere in the project:
import Header from '@/components/Header'      // ✅ clean
import Header from '../../../components/Header' // ❌ hard to read

Common mistakes

  • Two groups resolving to the same URL ((a)/about and (b)/about) → build error.
  • Expecting (admin) to protect pages → a group is only organisation; protect with auth checks (Auth lesson).
  • Multiple root layouts without a top app/layout.jsx → each group's layout must then include <html> and <body>.

Summary

  • (group) folders organise routes and allow separate layouts, without changing URLs.
  • _private folders are never routes.
  • Colocate page-specific components; use @/ for clean imports.
✅ Practice

Move your home and about pages into (marketing) and create (auth)/login with a centered-card layout. Confirm the URLs are still /about and /login.

Frequently Asked Questions

Does a route group change the URL?
No. A folder in parentheses like (marketing) is ignored in the URL. app/(marketing)/about/page.jsx is still /about.
What happens if two groups have the same page path?
You get a build error, because both would resolve to the same URL. For example (shop)/about and (marketing)/about cannot both exist.
Can I put components inside the app folder?
Yes. Only page.jsx and route.js make a folder public. Other files are safe to colocate, and a _folder makes the intention explicit.
← Next.js Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicloading, error & not-found Pages Your progress: 13 / 37 (35%) · Lesson 14 / 37 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free