Dynamic segments [param] for parameterized URLs like /blog/:slug and /users/:id.
A dynamic segment matches any value for a URL part. Wrap a folder or file name in square brackets, like [slug], to create one. Read the value with useParams(), which is auto-imported.
| Pattern | Example URL | Matches |
|---|---|---|
| [slug] | /blog/hello-world | slug = "hello-world" |
| [id] | /users/123 | id = "123" |
| [category]/[slug] | /blog/tech/hello-world | category = "tech", slug = "hello-world" |
Wrap a folder or file name in brackets to make a dynamic segment. The same pattern works for any folder in the tree.
You can nest dynamic folders. Each one becomes a property on the object returned by useParams().
Layouts can read dynamic params too, using useParams(). The layout itself does not create a URL.
A dynamic segment can also be a flat file, without a folder. Each file creates a URL directly.
When both a static route and a dynamic route match the same URL, the static route wins. Dynamic routes match only when no static route does.
| URL | Matched route |
|---|---|
| /blog/featured | Static - featured |
| /blog/hello-world | Dynamic - [slug] |
During npm run build, static routes are pre-rendered to real HTML. Dynamic routes are handled in one of three ways.
By default, a dynamic route that is not pre-rendered gets a shell page at its parent path. For /blog/:slug, that is /blog/. The shell relies on the client to render the page on visit. This is the fallback for every dynamic URL that is not pre-rendered.
Export staticParams from the dynamic page to pre-render specific URLs. The function can be sync or async, and returns an array of objects.
The returned objects are substituted into the route pattern. For /blog/[slug], { slug: 'hello-world' } becomes /blog/hello-world, which is written to dist/blog/hello-world/index.html.
Every page that is pre-rendered has its HTML scanned for internal <a href> links. Each new internal link is followed and rendered, with no depth limit. So if a rendered page links to /blog/hello-world, that URL is pre-rendered automatically without any configuration.
staticParams for URLs that nothing links to: a sitemap, an admin dashboard, or a dynamic route with data exports (which is client-only by default). For everything else, link crawling covers it.A project mixing static routes, dynamic routes, and a dynamic layout.
| URL | Matched route |
|---|---|
| /blog/featured | Static - featured |
| /blog/hello-world | Dynamic - [slug] |
| /users/123 | Dynamic - [id] |
| /users/123/settings | Nested dynamic - [id]/settings |
Define routes with folders and page files inside them.
Define routes with flat files instead of folders.
Match any number of trailing URL segments.
How every route is pre-rendered to HTML at build time.
Navigate between routes with Link, useNavigate, and prefetching.
Create your first pages and wrap them in shared layouts.
Dynamic segments [param] for parameterized URLs like /blog/:slug and /users/:id.
A dynamic segment matches any value for a URL part. Wrap a folder or file name in square brackets, like [slug], to create one. Read the value with useParams(), which is auto-imported.
| Pattern | Example URL | Matches |
|---|---|---|
| [slug] | /blog/hello-world | slug = "hello-world" |
| [id] | /users/123 | id = "123" |
| [category]/[slug] | /blog/tech/hello-world | category = "tech", slug = "hello-world" |
Wrap a folder or file name in brackets to make a dynamic segment. The same pattern works for any folder in the tree.
You can nest dynamic folders. Each one becomes a property on the object returned by useParams().
Layouts can read dynamic params too, using useParams(). The layout itself does not create a URL.
A dynamic segment can also be a flat file, without a folder. Each file creates a URL directly.
When both a static route and a dynamic route match the same URL, the static route wins. Dynamic routes match only when no static route does.
| URL | Matched route |
|---|---|
| /blog/featured | Static - featured |
| /blog/hello-world | Dynamic - [slug] |
During npm run build, static routes are pre-rendered to real HTML. Dynamic routes are handled in one of three ways.
By default, a dynamic route that is not pre-rendered gets a shell page at its parent path. For /blog/:slug, that is /blog/. The shell relies on the client to render the page on visit. This is the fallback for every dynamic URL that is not pre-rendered.
Export staticParams from the dynamic page to pre-render specific URLs. The function can be sync or async, and returns an array of objects.
The returned objects are substituted into the route pattern. For /blog/[slug], { slug: 'hello-world' } becomes /blog/hello-world, which is written to dist/blog/hello-world/index.html.
Every page that is pre-rendered has its HTML scanned for internal <a href> links. Each new internal link is followed and rendered, with no depth limit. So if a rendered page links to /blog/hello-world, that URL is pre-rendered automatically without any configuration.
staticParams for URLs that nothing links to: a sitemap, an admin dashboard, or a dynamic route with data exports (which is client-only by default). For everything else, link crawling covers it.A project mixing static routes, dynamic routes, and a dynamic layout.
| URL | Matched route |
|---|---|
| /blog/featured | Static - featured |
| /blog/hello-world | Dynamic - [slug] |
| /users/123 | Dynamic - [id] |
| /users/123/settings | Nested dynamic - [id]/settings |
Define routes with folders and page files inside them.
Define routes with flat files instead of folders.
Match any number of trailing URL segments.
How every route is pre-rendered to HTML at build time.
Navigate between routes with Link, useNavigate, and prefetching.
Create your first pages and wrap them in shared layouts.