Skip to main content
InterviewHubPRO
Section Overview
Q11

Question 11 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

22%
Astro Islands & SSR (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How do Dynamic Routes (`[slug].astro`) and `getStaticPaths()` work?

senior LevelCode ExampleAstro

In Simple Words: When generating static pages (SSG) for dynamic routes ([slug].astro):

astro
---
export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map(post => ({
    params: { slug: post.slug },
    props: { post }
  }));
}

const { post } = Astro.props;
const { Content } = await post.render();
---
<h1>{post.data.title}</h1>
<Content />