Static Generation

Getting the Sitemap

The Routable trait includes an associated [SITE_MAP] constant that contains the map of all of the routes in the enum.

By default, the sitemap is a tree of (static or dynamic) RouteTypes, but it can be flattened into a list of individual routes with the .flatten() method.

Generating a Sitemap

To statically render pages, we need to flatten the route tree and generate a file for each route that contains only static segments:


use dioxus::prelude::*;
use dioxus_router::prelude::*;

use dioxus_ssr::incremental::{DefaultRenderer, IncrementalRendererConfig};

async fn main() {
    let mut renderer = IncrementalRendererConfig::new()

        "SITE MAP:\n{}",
            .flat_map(|route| route.flatten().into_iter())
            .map(|route| {
                    .map(|segment| segment.to_string())

    pre_cache_static_routes::<Route, _>(
        &mut renderer,
        &DefaultRenderer {
            before_body: r#"<!DOCTYPE html>
        <html lang="en">
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width,
            <title>Dioxus Application</title>
            after_body: r#"</body>

fn Blog() -> Element {
    rsx! { div { "Blog" } }

fn Post(id: usize) -> Element {
    rsx! { div { "PostId: {id}" } }

fn PostHome() -> Element {
    rsx! { div { "Post" } }

fn Home() -> Element {
    rsx! { div { "Home" } }

#[derive(Clone, Debug, PartialEq, Routable)]
enum Route {
        Blog {},
        PostHome {},
        Post {
            id: usize,
    Home {},