---
title: Dynamic Routing in Astro
description: Learn how to enable dynamic rendering of new stories by setting up a catch-all route in Astro.
url: https://storyblok.com/docs/guides/astro/dynamic-routing
---

# Dynamic Routing in Astro

Set up a catch-all route in the Astro project to render new stories dynamically.

## Fetch and render a story dynamically

Create a `src/pages/[…slug].astro` file to fetch all stories in the space.

src/pages/\[…slug\].astro

```astro
---
import { useStoryblokApi } from "@storyblok/astro";
import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
import Layout from "../layouts/Layout.astro";

const { slug } = Astro.params;

const storyblokApi = useStoryblokApi();
const { data } = await storyblokApi.get(`cdn/stories/${slug || "home"}`, {
  version: "draft",
});

const story = data.story;
---

<Layout>
  <StoryblokComponent blok={story.content} />
</Layout>
```

Get the `slug` from the current route parameters, making an exception for the home story to be `/`.

With this approach, your project can automatically handle new stories you add to your space.

> [!TIP]
> Remove the `index.astro` file from the project.

> [!NOTE]
> To deploy in SSG mode, dynamic routes need to be manually defined. Use the [links endpoint](https://www.storyblok.com/docs/api/content-delivery/v2/links/) of the Content Delivery API and Astro’s `getStaticPaths()` to provide all routes. Learn more about [dynamic routes in the Astro documentation](https://docs.astro.build/en/guides/routing/#dynamic-routes).

## Related resources

[Dynamic Routes in Astro](https://docs.astro.build/en/guides/routing/#dynamic-routes)

[Content Delivery API: Retrieve a Single Story](/docs/api/content-delivery/v2/stories/retrieve-a-single-story)

[Content Delivery API: Retrieve Multiple Stories](/docs/api/content-delivery/v2/stories/retrieve-multiple-stories)

  

## Pagination

-   [Previous: Visual Preview in Astro](/docs/guides/astro/visual-preview)
-   [Next: Content Modeling in Astro](/docs/guides/astro/content-modeling)
