I'm having trouble with dynamic routing in Astro. I'm working with a Content Collection called "Articles" and then created a route: [slug].astro. However, the slug does not resolve to the markdown content, and every time I've run my dev server it resolves to a 404 page, despite my code editor validating that the data has been imported from my Collection folder into the "pages" subdirectory.
From my content/config.ts file:
const articles = defineCollection ({
type: "content",
schema: ( {image} ) => z.object({
title: z.string(),
category: reference("sections"),
cover: image(),
coverAlt: z.string().optional(),
description: z.string(),
date: z.date(),
identifier: z.number(),
seaslug: z.string().optional(),
})
})
export const collections = {
articles,
}
From my articles/[slug].astro file:
---
import { getEntry, getCollection } from "astro:content";
export async function getStaticPaths() {
const articles = await getCollection('articles');
return articles.map((p) => ({
params: { slug: p.slug },
}));
}
const { slug } = Astro.params;
const articles = await getEntry("articles", slug)
const { Content } = await articles.render();
---
<h1>{articles.data.title}</h1>
<Content />
loaderin thedefineCollectioncall? See docs.astro.build/en/tutorial/6-islands/4/…