Dynamic Routes from Data
You'll learn how to automatically generate multiple pages—like blog posts or product listings—from a data source at build time, instead of hand-coding each route.
The Core Idea
Imagine you have 500 blog posts stored in a CMS or Markdown files. You don't want to manually create 500 separate HTML files. Instead, you define one template and tell your build system: "For each post in my data, create a page using this template."
This is dynamic route generation—your build process reads a data structure (array of posts, products, profiles) and creates a static page for each item automatically.
How It Works
Think of it like a mail-merge for web pages. You provide:
- A data source: An array from your CMS, GraphQL query results, or parsed Markdown files
- A template: A page component that knows how to display one item
- Path rules: How to convert each data item into a URL (e.g.,
/blog/post-slug)
At build time, your static site generator iterates through the data, applies the template to each item, and outputs individual HTML files—one per route.
Real-World Example
You query your headless CMS at build time and get back 50 product objects. Each has a slug field. Your build system generates:
/products/laptop→ page for laptop product/products/phone→ page for phone product- (48 more pages...)
Each uses the same template but with different data injected.
This combines the power of getStaticPaths (defining which routes exist) with build-time data fetching (getting the actual content for each route).
Key Takeaway: Dynamic routes from data automate page creation by mapping data structures to URL paths at build time, turning hundreds of content items into individually optimized static pages without manual duplication.