Dynamic Routing
⏱ Estimated reading time: 2 min
Dynamic routing in Next.js allows you to create pages with dynamic URLs using route parameters. It is commonly used for blogs, product pages, user profiles, and any content that depends on dynamic data.
1. What is Dynamic Routing?
Dynamic routes are created using square brackets [ ] in the folder or file name.
The value inside the brackets becomes a route parameter.
2. Dynamic Routes in App Router
Example: Single Dynamic Segment
This route will match:
Accessing Params
3. Multiple Dynamic Segments
URL example:
4. Catch-All Routes
Catch-all routes match multiple path segments.
Example URLs:
5. Optional Catch-All Routes
Optional catch-all routes also match the root path.
Matches:
6. Generating Static Params
For static generation of dynamic routes:
7. Dynamic Routes in Pages Router (Older)
Access parameter:
Use Cases
-
Blog posts
-
Product details pages
-
User profiles
-
Documentation pages
Conclusion
Dynamic routing in Next.js makes it easy to build flexible and scalable applications. With support for single, multiple, and catch-all routes, you can handle complex URL structures efficiently.
Register Now
Share this Post
← Back to Tutorials