#folders in content collections

3 messages · Page 1 of 1 (latest)

tall stoneBOT
#

Hi @solemn remnant. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, you can use any folder name for your content collection, and the folder name itself does not automatically become part of the URL for your generated pages. In Astro, content collections are stored outside of the src/pages/ directory, and no routes are generated by default for collection items. You define the folder structure (e.g., src/interior-pages/), and then manually create dynamic routes in src/pages/ to map your content entries to whatever URLs you want.

For example, you might have a collection like src/interior-pages/ and define it in your content.config.ts. When generating routes, you use dynamic route files (e.g., src/pages/[...slug].astro) and control the URL structure yourself by mapping the collection entries to the desired URLs in your getStaticPaths or SSR logic. The folder name (interior-pages) is just for organization and does not dictate the URL unless you explicitly use it in your routing logic.

This approach is described in the documentation:

Content collections are stored outside of the src/pages/ directory. This means that no pages or routes are generated for your collection items by default. You will need to manually create a new dynamic route if you want to generate HTML pages for each of your collection entries, such as individual blog posts. Your dynamic route will map the incoming request param (e.g. Astro.params.slug in src/pages/blog/[...slug].astro) to fetch the correct entry for each page.
Generating Routes from Content

#

So, you are free to use a folder name like interior-pages for your collection, and then map its content to any URLs you need. The folder name is not automatically part of the URL unless you make it so in your routing logic.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: