Astro Islands & SSR (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Dynamic Routing & `getStaticPaths()` in Astro.
senior LevelCode ExampleRoutingSystem DesignAstro
In Simple Words:
In static mode (output: 'static'), dynamic routes (src/pages/posts/[slug].astro) must export a getStaticPaths() function returning an array of all parameters and props to pre-render at build time.
astro
---
export async function getStaticPaths() {
const posts = await getCollection('blog');
return posts.map(post => ({
params: { slug: post.slug },
props: { post }
}));
}
const { post } = Astro.props;
---
<h1>{post.data.title}</h1>