When you don't know the exact segment names ahead of time and want to create routes from dynamic data, you can use Dynamic Segments that are filled in at request time or prerendered at build time.
A Dynamic Segment can be created by wrapping a folder’s name in square brackets: [folderName]
. For example, [id]
or [slug]
.
Dynamic Segments are passed as the params
prop to layout
, page
, route
, and generateMetadata
functions.
For example, a simple blog could include the following route app/blog/[slug]/page.js
where [slug]
is the Dynamic Segment for blog posts.
//app/blog/[slug]/ppage.js
export default function Page({ params }) { return <div>My Post</div>;}
See the generateStaticParams() page to learn how to generate the params for the segment.