Dynamic Routes

Dynamic Routes

Sol SSG supports dynamic route generation using the _param_ directory naming pattern. This allows you to generate multiple static pages from a single template.

Basic Usage

Directory Structure

docs/
โ””โ”€โ”€ posts/
    โ”œโ”€โ”€ index.md              # Posts listing page
    โ””โ”€โ”€ _slug_/               # Dynamic parameter directory
        โ”œโ”€โ”€ page.json         # Static params configuration
        โ””โ”€โ”€ index.md          # Template for each page

Configuration (page.json)

Define which pages to generate using staticParams:

{
  "staticParams": [
    { "slug": "hello-world" },
    { "slug": "getting-started" },
    { "slug": "advanced-topics" }
  ]
}

Template (index.md)

The template file is used for all generated pages:

---
description: A blog post
---

# Post Page

This content is shared across all generated pages.

Generated Output

With the above configuration, Sol SSG generates:

  • /posts/hello-world/index.html

  • /posts/getting-started/index.html

  • /posts/advanced-topics/index.html

Parameter Naming

The parameter name is extracted from the directory name:

DirectoryParameter
_slug_slug
_id_id
_category_category

Auto-Generated Titles

If no title is specified in frontmatter, Sol SSG generates one from the parameter value:

  • hello-world โ†’ "Hello World"

  • getting-started โ†’ "Getting Started"

Multiple Parameters

You can use multiple parameters in nested directories:

docs/
โ””โ”€โ”€ blog/
    โ””โ”€โ”€ _category_/
        โ””โ”€โ”€ _slug_/
            โ”œโ”€โ”€ page.json
            โ””โ”€โ”€ index.md
{
  "staticParams": [
    { "category": "tech", "slug": "intro-to-moonbit" },
    { "category": "tech", "slug": "advanced-patterns" },
    { "category": "news", "slug": "release-notes" }
  ]
}

Comparison with Client-Side Routing

FeatureDynamic Routes (_slug_)Client-Side (BrowserRouter)
SEOFull static HTMLInitial page only
Build timeGenerates all pagesSingle entry point
NavigationFull page reloadSPA-like instant
Use caseBlog posts, docsInteractive apps

For client-side dynamic routing (SPA), see Islands.