Skip to content

Pages & Routing

Astro uses file-based routing from src/pages/.

Examples:

src/pages/index.astro -> /
src/pages/about.astro -> /about
src/pages/blog/first-post.md -> /blog/first-post

Dynamic routes:

src/pages/blog/[slug].astro -> /blog/my-post

Collection routes with getStaticPaths:

---
export async function getStaticPaths() {
const slugs = ["hello", "world"];
return slugs.map((slug) => ({ params: { slug } }));
}
const { slug } = Astro.params;
---
<h1>Post: {slug}</h1>