Dynamic Routes with Static Generation
You'll learn how to pre-build individual pages for dynamic content (like blog posts or products) at build time, so every URL is ready before anyone visits.
The Core Idea
When building a blog or e-commerce site, you don't want to manually create a separate file for every post or product. Instead, you define a template page with a dynamic route (like /blog/[slug] or /product/[id]), then tell your build process: "fetch all my posts/products, and generate a static HTML file for each one."
At build time, your static site generator:
- Queries your data source (database, CMS, JSON files)
- Gets a list of all items (e.g., 50 blog posts)
- For each item, creates a unique HTML page using your template
- Outputs static files like
/blog/getting-started.html,/blog/advanced-tips.html, etc.
How It Works in Practice
During the build, you provide two things:
- A list of paths to generate (e.g., all post slugs:
['intro', 'tutorial', 'guide']) - The data for each path (fetched once per item at build time)
The result? A fully static site where /blog/intro, /blog/tutorial, and /blog/guide already exist as HTML files on your CDN—no server computation needed when users visit.
The Analogy
Imagine printing a catalog. You have one template design, but you print a separate page for every product in your inventory before shipping. Customers flip directly to any page instantly—no waiting for pages to be "rendered" on demand.
Key Takeaway: Dynamic routes with static generation let you pre-build thousands of individual pages from data sources at build time, combining the flexibility of dynamic content with the speed of static hosting.