Learn/Next.js/Chapter 5

Chapter 5 of 21

Continue learning Next.js step by step.

24%
Chapter 5

Routing

Learn how file-based routing works in Next.js.

Theory

Next.js uses file-system based routing. Folders inside the app directory can represent URL segments. For example, app/about/page.tsx creates the /about route.

Example

app/
├── page.tsx
├── about/
│   └── page.tsx
└── contact/
    └── page.tsx

Output

/about and /contact become available as application routes.

Practice

Create Home, About and Contact routes.

Interview Questions

1

How does routing work in Next.js?

2

What is file-based routing?

3

How do you create an About route?

Quick Quiz

Which option best describes this chapter?

A.File-system based routing
B.Database routing
C.CSS routing
D.Browser-only routing