skip to content
Alvin Lucillo

Multiple path params

/ 1 min read

💻 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:

  1. Make sure your markdown files are in the desired structure
  2. Create these structure under pages: posts/[year]/[month]/[day].astro. The parts in square brackets represent dynamic path parameters.
  3. Provide the parameter values to the getStaticPaths function. getAllPosts uses getCollection and 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.