Dynamic Routes

Generate multiple pages from a single markdown template using paths loader files

Generate many pages from a single markdown file and dynamic data. Useful for blogs, package docs, or any data-driven pages.

Basic Setup

Create a template file with parameter in brackets and a paths loader:

.
└─ packages/
   ├─ [pkg].md           # Route template
   └─ [pkg].paths.js     # Paths loader

The paths loader exports a paths method returning route parameters:

// packages/[pkg].paths.js
export default {
  paths() {
    return [
      { params: { pkg: 'foo' }},
      { params: { pkg: 'bar' }},
      { params: { pkg: 'baz' }}
    ]
  }
}

Generated pages:

  • /packages/foo.html

  • /packages/bar.html

  • /packages/baz.html

Multiple Parameters

Dynamic Path Generation

From local files:

From remote API:

Accessing Params in Page

Template globals:

In script:

Passing Content

For heavy content (raw markdown/HTML from CMS), use content instead of params to avoid bloating the client bundle:

Render content in template:

The <!-- @content --> placeholder is replaced with the content from the paths loader.

Watch Option

Auto-rebuild when template or data files change:

Complete Example: Blog

Key Points

  • Template file uses [param] syntax in filename

  • Paths loader file must be named [param].paths.js or .ts

  • paths() returns array of { params: {...}, content?: string }

  • Use $params in templates or useData().params in scripts

  • Use content for heavy data to avoid client bundle bloat

  • watch enables HMR for template/data file changes

Last updated

Was this helpful?