DocsPluginsShowcaseReleases
npmStar us on GitHub

Getting Started

IntroductionInstallationProject StructureLayouts and PagesLinking and Navigating

Routing

Folder-Based RoutingFile-Based RoutingDynamic RoutesParallel RoutesIntercepting RoutesCatch-All RoutesMDX & Markdown Pages

Special Files

Loading UIError BoundariesTemplateDefaultNot Found

Data Fetching

LoadersActionsAccessing Route Data

Metadata

Metadata & SEOOpen Graph & TwitterIcons & Favicons

API Routes

API Routes OverviewPlain Function HandlersHono IntegrationDynamic API Routes

Environment Variables

OverviewPrefixes & Client ExposureUsing in API Routes

Styling

CSS OverviewTailwind CSSCSS Modules

Platforms

WebWindowsmacOSLinuxAndroidiOS

Deployment

Deployment OverviewProduction ServerStatic ExportHosting Providers

A native React framework for building cross-platform applications from a single codebase.

Resources

  • Documentation
  • Plugins
  • Showcase
  • Releases

Community

  • GitHub Discussions
  • Reddit
  • Discord
  • LinkedIn

More

  • npm
  • GitHub
  • Issues
  • License

© 2026 Bini Cooperation.

Dynamic Routes

Dynamic segments [param] for parameterized URLs like /blog/:slug and /users/:id.

Overview

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.

PatternExample URLMatches
[slug]/blog/hello-worldslug = "hello-world"
[id]/users/123id = "123"
[category]/[slug]/blog/tech/hello-worldcategory = "tech", slug = "hello-world"

Dynamic Segments

Wrap a folder or file name in brackets to make a dynamic segment. The same pattern works for any folder in the tree.

app
blog
[slug]
page.tsx
users
[id]
page.tsx
/blog/:slugRoutable
/users/:idRoutable
src/app/blog/[slug]/page.tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()

  return <h1>Post: {slug}</h1>
}

Multiple Parameters

You can nest dynamic folders. Each one becomes a property on the object returned by useParams().

app
blog
[category]
[slug]
page.tsx
/blog/:category/:slugRoutable
src/app/blog/[category]/[slug]/page.tsx
export default function BlogPost() {
  const { category, slug } = useParams<{
    category: string
    slug: string
  }>()

  return (
    <div>
      <p>Category: {category}</p>
      <h1>Post: {slug}</h1>
    </div>
  )
}

Dynamic Segments in Layouts

Layouts can read dynamic params too, using useParams(). The layout itself does not create a URL.

app
blog
[slug]
layout.tsx
page.tsx
-Not Routable
/blog/:slugRoutable
src/app/blog/[slug]/layout.tsx
import { Outlet } from 'react-router-dom'

export default function BlogLayout() {
  const { slug } = useParams<{ slug: string }>()

  return (
    <div>
      <header>
        <h2>Post: {slug}</h2>
        <Link to="/blog">Back to blog</Link>
      </header>
      <main><Outlet /></main>
    </div>
  )
}

Flat File Dynamic Routes

A dynamic segment can also be a flat file, without a folder. Each file creates a URL directly.

app
blog
[slug].tsx
users
[id].tsx
/blog/:slugRoutable
/users/:idRoutable
src/app/blog/[slug].tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()
  return <h1>Post: {slug}</h1>
}

Route Priority

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.

app
blog
featured
page.tsx
[slug]
page.tsx
/blog/featuredRoutable
/blog/:slugRoutable
URLMatched route
/blog/featuredStatic - featured
/blog/hello-worldDynamic - [slug]

Static Generation

During npm run build, static routes are pre-rendered to real HTML. Dynamic routes are handled in one of three ways.

1. Shell page

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.

2. staticParams

Export staticParams from the dynamic page to pre-render specific URLs. The function can be sync or async, and returns an array of objects.

src/app/blog/[slug]/page.tsx
export async function staticParams() {
  const posts = await getPosts()
  return posts.map((post) => ({ slug: post.slug }))
}

export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()
  return <h1>Post: {slug}</h1>
}

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.

3. Link crawling

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.

Use 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.

Complete Example

A project mixing static routes, dynamic routes, and a dynamic layout.

app
blog
featured
page.tsx
[slug]
layout.tsx
page.tsx
users
[id]
page.tsx
settings
page.tsx
/blog/featuredRoutable
-Not Routable
/blog/:slugRoutable
/users/:idRoutable
/users/:id/settingsRoutable
URLMatched route
/blog/featuredStatic - featured
/blog/hello-worldDynamic - [slug]
/users/123Dynamic - [id]
/users/123/settingsNested dynamic - [id]/settings

Folder-Based Routing

Define routes with folders and page files inside them.

File-Based Routing

Define routes with flat files instead of folders.

Catch-All Routes

Match any number of trailing URL segments.

Static Export

How every route is pre-rendered to HTML at build time.

Linking and Navigating

Navigate between routes with Link, useNavigate, and prefetching.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Was this helpful?
PreviousFile-Based Routing
NextParallel Routes

On this page

  • Overview
  • Dynamic Segments
  • Multiple Parameters
  • Dynamic Segments in Layouts
  • Flat File Dynamic Routes
  • Route Priority
  • Static Generation
  • Complete Example
Edit this page on GitHub

Dynamic Routes

Dynamic segments [param] for parameterized URLs like /blog/:slug and /users/:id.

Overview

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.

PatternExample URLMatches
[slug]/blog/hello-worldslug = "hello-world"
[id]/users/123id = "123"
[category]/[slug]/blog/tech/hello-worldcategory = "tech", slug = "hello-world"

Dynamic Segments

Wrap a folder or file name in brackets to make a dynamic segment. The same pattern works for any folder in the tree.

app
blog
[slug]
page.tsx
users
[id]
page.tsx
/blog/:slugRoutable
/users/:idRoutable
src/app/blog/[slug]/page.tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()

  return <h1>Post: {slug}</h1>
}

Multiple Parameters

You can nest dynamic folders. Each one becomes a property on the object returned by useParams().

app
blog
[category]
[slug]
page.tsx
/blog/:category/:slugRoutable
src/app/blog/[category]/[slug]/page.tsx
export default function BlogPost() {
  const { category, slug } = useParams<{
    category: string
    slug: string
  }>()

  return (
    <div>
      <p>Category: {category}</p>
      <h1>Post: {slug}</h1>
    </div>
  )
}

Dynamic Segments in Layouts

Layouts can read dynamic params too, using useParams(). The layout itself does not create a URL.

app
blog
[slug]
layout.tsx
page.tsx
-Not Routable
/blog/:slugRoutable
src/app/blog/[slug]/layout.tsx
import { Outlet } from 'react-router-dom'

export default function BlogLayout() {
  const { slug } = useParams<{ slug: string }>()

  return (
    <div>
      <header>
        <h2>Post: {slug}</h2>
        <Link to="/blog">Back to blog</Link>
      </header>
      <main><Outlet /></main>
    </div>
  )
}

Flat File Dynamic Routes

A dynamic segment can also be a flat file, without a folder. Each file creates a URL directly.

app
blog
[slug].tsx
users
[id].tsx
/blog/:slugRoutable
/users/:idRoutable
src/app/blog/[slug].tsx
export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()
  return <h1>Post: {slug}</h1>
}

Route Priority

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.

app
blog
featured
page.tsx
[slug]
page.tsx
/blog/featuredRoutable
/blog/:slugRoutable
URLMatched route
/blog/featuredStatic - featured
/blog/hello-worldDynamic - [slug]

Static Generation

During npm run build, static routes are pre-rendered to real HTML. Dynamic routes are handled in one of three ways.

1. Shell page

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.

2. staticParams

Export staticParams from the dynamic page to pre-render specific URLs. The function can be sync or async, and returns an array of objects.

src/app/blog/[slug]/page.tsx
export async function staticParams() {
  const posts = await getPosts()
  return posts.map((post) => ({ slug: post.slug }))
}

export default function BlogPost() {
  const { slug } = useParams<{ slug: string }>()
  return <h1>Post: {slug}</h1>
}

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.

3. Link crawling

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.

Use 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.

Complete Example

A project mixing static routes, dynamic routes, and a dynamic layout.

app
blog
featured
page.tsx
[slug]
layout.tsx
page.tsx
users
[id]
page.tsx
settings
page.tsx
/blog/featuredRoutable
-Not Routable
/blog/:slugRoutable
/users/:idRoutable
/users/:id/settingsRoutable
URLMatched route
/blog/featuredStatic - featured
/blog/hello-worldDynamic - [slug]
/users/123Dynamic - [id]
/users/123/settingsNested dynamic - [id]/settings

Folder-Based Routing

Define routes with folders and page files inside them.

File-Based Routing

Define routes with flat files instead of folders.

Catch-All Routes

Match any number of trailing URL segments.

Static Export

How every route is pre-rendered to HTML at build time.

Linking and Navigating

Navigate between routes with Link, useNavigate, and prefetching.

Layouts and Pages

Create your first pages and wrap them in shared layouts.

Was this helpful?
PreviousFile-Based Routing
NextParallel Routes

On this page

  • Overview
  • Dynamic Segments
  • Multiple Parameters
  • Dynamic Segments in Layouts
  • Flat File Dynamic Routes
  • Route Priority
  • Static Generation
  • Complete Example
Edit this page on GitHub