How is a route formed in the app router?
In the Next.js App Router, a route is formed exclusively by the folder structure and special files inside the app/ directory.
The key idea:
URL = the path of folders from
app/topage.tsx
Basic rule
Every route is a folder that contains a file:
page.tsx
Example:
app/page.tsx → /
app/blog/page.tsx → /blog
app/blog/post/page.tsx → /blog/postWhat is taken into account when forming a route
1. Folders
Every folder adds a URL segment:
app/products/shoes/page.tsx → /products/shoes2. page.tsx
- a required file for the route
- it is what forms the page
- without it, the folder is not a route
3. Dynamic segments
Square brackets are used:
app/blog/[slug]/page.tsx → /blog/anything[slug]→ route parameter- available on the server and client
4. Catch-all segments
app/docs/[...slug]/page.tsxURL:
/docs/a/docs/a/b/c
5. Optional catch-all
app/docs/[[...slug]]/page.tsxURL:
/docs/docs/a/docs/a/b
6. Route Groups (do not affect the URL)
app/(auth)/login/page.tsx → /login- a folder in
() - used only for structure
- does not end up in the URL
7. layout.tsx
- does not add a URL segment
- sets the shared shell
- inherited by nested routes
8. Special files
They do not affect the URL, but participate in rendering:
| File | Purpose |
|---|---|
layout.tsx | Shared layout |
loading.tsx | Suspense loading |
error.tsx | Error boundary |
not-found.tsx | 404 |
template.tsx | State reset |
Example of a complex route
app/
├─ (marketing)/
│ └─ blog/
│ └─ [slug]/
│ ├─ page.tsx
│ └─ layout.tsx
└─ (auth)/
└─ login/
└─ page.tsxResult:
/blog/my-post/login
Common mistake
Thinking that a folder without
page.tsxis a route A route exists only whenpage.tsxis present
Short interview answer
In the App Router, a route is formed based on the path of folders from
app/topage.tsx, with support for dynamic segments, route groups, and special files that control rendering but do not affect the URL.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.