Course contentsShow
← Web Development
Lesson 1771 of 2,98233. Static Site Generation and JamstackFree lesson

Dynamic Routes with Static Generation

Generating multiple pages from dynamic data sources: creating a page for every blog post, product, or user at build time.

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:

  1. Queries your data source (database, CMS, JSON files)
  2. Gets a list of all items (e.g., 50 blog posts)
  3. For each item, creates a unique HTML page using your template
  4. 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.