#astro
#routing
#demo
This is my very first blog post using Astro's dynamic routing!
/blog/[slug].astro (dynamic route)
/blog/[any-slug-here]
"my-first-post"
This is my very first blog post using Astro's dynamic routing!
/blog/create
Static Route
Goes to create.astro (blog creation form)
/blog/my-first-post
Dynamic Route
Goes to [slug].astro (this page)
---
// File: /blog/[slug].astro
export const prerender = false; // SSR for dynamic content
const { slug } = Astro.params;
// In real app: query database/CMS
const post = await getPostBySlug(slug);
if (!post) {
return Astro.redirect('/404');
}
---
<Layout title={post.title}>
<h1>{post.title}</h1>
<p>Slug: {slug}</p>
<div>{post.content}</div>
</Layout> Try these URLs to see how the dynamic route handles different slugs: