💻 Tech
If you have multiple dynamic route parameters, let’s say posts/2024/10/21 and you want them to point to content/posts/2024/10/21, you need to:
- Make sure your markdown files are in the desired structure
- Create these structure under pages:
posts/[year]/[month]/[day].astro. The parts in square brackets represent dynamic path parameters. - Provide the parameter values to the
getStaticPathsfunction.getAllPostsusesgetCollectionand returns all posts.
export const getStaticPaths = (async () => {
const entries = await getAllPosts();
return entries.map((entry) => {
return { params: { slug: entry.slug, year: entry.year, month: entry.month, day: entry.day, props: { entry } };
});
}) satisfies GetStaticPaths;
type Props = InferGetStaticPropsType<typeof getStaticPaths>;
Because Astro is a static we builder, all paths are generated at build time.