Agent context packet

Structured metadata, source alternates, graph links, headings, series position, and diagram inventory for crawlers and agent readers.

Table of contents

  1. The Rule
  2. Static Pages
  3. Index Pages
  4. Dynamic Routes: [...slug].astro
  5. What Happens During Build
  6. Sources

Series context

Learn Astro 6

A ground-up guide to Astro for developers coming from Python, LaTeX, or scientific computing.

  1. The Mental Model
  2. File-Based Routing
  3. .astro Files
  4. Components
  5. Astro Layouts
  6. Content Collections
  7. Astro Styling
  8. Markdown and Code Blocks
  9. Build and Deploy

Entry facts

Kind
guide
Maturity
evergreen
Confidence
high
Origin
ai-drafted (AI-drafted, human-reviewed)
Author
Agent
Directed by
krow
Published
Modified
Words
608 (3 min read)
Series
learn-astro #2
Tags
astro, fundamentals
Prerequisites
Full corpus
/llms-full.txt
Readable corpus
/source/full-corpus/

Graph links

Prerequisites astro-mental-model

Tagsastro, fundamentals

Diagram inventory

  1. The Rule Mermaid SVG, Mermaid source, ASCII companion

File-Based Routing

The file system IS the router. No config files, no URL mapping — just directories and files.

/ directed by / / 3 min read
On this page

The Rule

If you are new to Astro, start with the mental model. After this, the next step is .astro files, then components and layouts.

Every file in src/pages/ becomes a URL. The directory structure maps directly to the URL path.

Each file in src/pages becomes a URL. index.astro serves the root, about.astro the about page, and the dynamic [kind]/[...slug].astro renders one URL per entry.

File-based routing — pages to URLsEach file in src/pages becomes a URL. index.astro serves the root, about.astro the about page, and the dynamic [kind]/[...slug].astro renders one URL per entry.

src/pages/index.astro

/

src/pages/about.astro

/about/

src/pages/[kind]/[...slug].astro

/guide/astro-mental-model/ (dynamic)

File-based routing — pages to URLs

That’s it. No routing config. No urls.py. No app.get('/blog/:id'). The filesystem is the router.

Analogy

This is like how Apache/nginx serve files from a directory. If you put blog/index.html in the document root, visiting /blog/ serves that file. Astro does the same thing, but compiles .astro files to .html first.

Static Pages

A file like src/pages/about.astro generates exactly one HTML page at /about/. You write it, Astro compiles it, done.

src/pages/about.astro
---
// This code runs at build time
const title = "About krowdev";
---
<html>
<body>
<h1>{title}</h1>
<p>A developer knowledge base.</p>
</body>
</html>

Index Pages

index.astro in any directory becomes the default page for that path:

  • src/pages/index.astro/ (homepage)
  • src/pages/[kind]/[...slug].astro/guide/astro-mental-model/
Analogy

Same as index.html in traditional web hosting, or __init__.py in a Python package — it’s what you get when you navigate to the directory itself.

Dynamic Routes: [...slug].astro

This is where it gets powerful. Square brackets mean “parameterized.” The ... means “catch all path segments.”

src/pages/[kind]/[...slug].astro can generate:

  • /guide/agentic-coding-getting-started/
  • /guide/agentic-coding-prompt-patterns/
  • /guide/astro-mental-model/

But Astro needs to know which pages to generate at build time. That’s what getStaticPaths() does:

src/pages/[kind]/[...slug].astro
---
export async function getStaticPaths() {
const entries = await getCollection('kb');
// Return one path per kb entry
return entries.map(entry => ({
params: { kind: entry.data.kind, slug: entry.id }, // what goes in the URL
props: { entry }, // data passed to the page
}));
}
---
Analogy

Think of getStaticPaths() as a Makefile pattern rule. Instead of writing one rule per file:

dist/guide/getting-started.html: content/kb/getting-started.md
dist/guide/prompt-patterns.html: content/kb/prompt-patterns.md

You write one pattern:

dist/guide/%.html: content/kb/%.md
$(COMPILE) $< -o $@

getStaticPaths() is telling Astro: “here are all the % values — generate one page for each.”

What Happens During Build

When you run npm run build:

  1. Astro scans src/pages/
  2. Static pages (index.astro, about.astro) → compiled once each
  3. Dynamic pages ([...slug].astro) → getStaticPaths() is called → one HTML file per returned path
  4. All output lands in dist/
Build:
src/pages/index.astro → dist/index.html
src/pages/[kind]/[...slug].astro → dist/guide/agentic-coding-getting-started/index.html
→ dist/guide/astro-mental-model/index.html
→ dist/article/welcome-to-krowdev/index.html
→ ... (one per kb entry)
Challenge: Trace the route

Look at krowdev’s actual page files:

Terminal window
find src/pages -name "*.astro" | sort

For each file, write down:

  1. What URL(s) does it generate?
  2. Is it static (one page) or dynamic (many pages)?
  3. If dynamic, what collection does it iterate over?
Answer
FileURL(s)Type
pages/index.astro/Static (1 page)
pages/[kind]/[...slug].astro/guide/astro-mental-model/, /article/welcome-to-krowdev/, …Dynamic (1 per kb entry)

Sources

Diagram

Drag to pan · scroll or pinch to zoom · Esc to close