Dynamic Routing and Custom Content Rendering
Learn how we can use content collections in Astro to generate dynamic routes.
Astro has built-in functions to fetch content collections, making it easy to generate dynamic routes based on the available Markdown files inside a project. Using Markdown files as a way to store content for our project enables us to keep the code and content of the project in one place.
For a smaller project, this can mean reduced costs and simpler infrastructures because no CMS is needed for managing pages. On the other hand, content editors need to have knowledge about Markdown in order to work with content collections. In this lesson, we’ll take a look at how to render content collections as individual pages and how to use their frontmatter data to render custom components.
Fetching a content collection
To fetch content collections in Astro, we can use the built-in getCollection
function, which expects the name of the collection folder as the first parameter, also called a collection entry.
Get hands-on with 1400+ tech skills courses.