Learn/Next.js/Chapter 6

Chapter 6 of 21

Continue learning Next.js step by step.

29%
Chapter 6

Dynamic Routes

Learn how to create dynamic URL segments in Next.js.

Theory

Dynamic routes allow a route to display different content based on a URL parameter. A folder such as [slug] represents a dynamic segment. For example, /blog/hello and /blog/nextjs can use the same dynamic page.

Example

app/blog/[slug]/page.tsx

Output

Different slug values can be handled by the same dynamic route.

Practice

Create a blog/[slug] dynamic route.

Interview Questions

1

What are dynamic routes?

2

What does [slug] mean?

3

Where are dynamic routes useful?

Quick Quiz

Which option best describes this chapter?

A.[slug]
B.(slug)
C.{slug}
D.<slug>