File-based routing

pages router

The pages directory holds routes as files and nested files.

A file creates a route of the same name. For example, users.tsx in pages/ creates the users route.

users

If the file lives in a nested directory, the directory names appear in the path. E.g. for settings/main.tsx:

settings/main

Index files don't come with a name. Instead, they match the path of their parent. E.g. for users/index.tsx:

users ## index file for users/

route conflict

As seen above, a standard route may clash with one created by a nested index:

users ## users.tsx
users ## users/index.tsx

Next.js detects such conflict and requests us to resolve it.

earlymorning logo

© Antoine Weber 2026 - All rights reserved

File-based routing

pages router

The pages directory holds routes as files and nested files.

A file creates a route of the same name. For example, users.tsx in pages/ creates the users route.

users

If the file lives in a nested directory, the directory names appear in the path. E.g. for settings/main.tsx:

settings/main

Index files don't come with a name. Instead, they match the path of their parent. E.g. for users/index.tsx:

users ## index file for users/

route conflict

As seen above, a standard route may clash with one created by a nested index:

users ## users.tsx
users ## users/index.tsx

Next.js detects such conflict and requests us to resolve it.