Pages and routing

Use nested and index pages

Create clean directory routes and choose an index file when the URL should end at a folder.

8 minute lesson

~~~

An index page represents the folder URL.

src/pages/blog/index.astro   → /blog/
src/pages/blog/archive.astro → /blog/archive/

This mirrors a familiar static-site structure and keeps related routes together.

A deeper index works the same way:

src/pages/docs/api/index.astro → /docs/api/

Use folders when they reflect the public information hierarchy. Do not nest files only to organize the source if you do not want that nesting in the URL.

Shared components do not belong under src/pages/ unless they should become routes. Put a reusable blog card under src/components/, not beside page files where it could be mistaken for a public page.

Move a page into a folder and run the build. Confirm the old URL no longer exists, then add a redirect when the URL was already public.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →