To add a page to an Astro theme, create a .astro file in src/pages/ (the file path becomes the URL), wrap its content in the theme’s existing layout so it gets the same head, header and footer, build the body from the theme’s section components, and add a link to the navigation. A file at src/pages/services.astro is served at /services/.
Key Takeaways
- File-based routing: the path under
src/pages/is the URL. No router config to edit.- Always use the theme’s layout component, so meta tags, fonts and styles come along.
- Reuse existing sections (hero, features, CTA) instead of writing new markup.
- New pages don’t appear in the menu automatically; edit the navigation data too.
Step 1: create the file
Pick the URL first, then create the matching file:
src/pages/services.astro -> /services/
src/pages/services/audits.astro -> /services/audits/
src/pages/legal/privacy.md -> /legal/privacy/
Markdown files in src/pages/ work too, which is handy for plain text pages like a privacy policy. The pages and routing docs cover dynamic routes if you need a page per item.
Step 2: wrap it in the theme’s layout
Open an existing page, such as src/pages/about.astro, and copy its layout import and props. That’s the fastest way to learn what the layout expects:
---
// src/pages/services.astro
import BaseLayout from '../layouts/BaseLayout.astro';
---
<BaseLayout
title="Services | Northline Studio"
description="Brand strategy, web design and Astro builds for independent hotels."
>
<section class="container mx-auto px-6 py-20">
<h1 class="text-4xl font-semibold">Services</h1>
<p class="mt-4 max-w-2xl text-lg">What we do and how we work.</p>
</section>
</BaseLayout>
Give every page a unique title and description. The layout turns them into <title> and meta tags, and duplicates hurt search snippets.
Step 3: build the body from existing sections
Themes ship section components for their own pages. Look in src/components/ (often a sections/ folder) and reuse them:
---
// src/pages/services.astro
import BaseLayout from '../layouts/BaseLayout.astro';
import PageHero from '../components/sections/PageHero.astro';
import FeatureGrid from '../components/sections/FeatureGrid.astro';
import CallToAction from '../components/sections/CallToAction.astro';
const services = [
{ title: 'Brand strategy', text: 'Positioning, naming and voice.' },
{ title: 'Web design', text: 'Layouts built around your bookings.' },
{ title: 'Astro builds', text: 'Fast static sites you own outright.' },
];
---
<BaseLayout title="Services | Northline Studio" description="Brand strategy, web design and Astro builds.">
<PageHero title="Services" subtitle="What we do and how we work." />
<FeatureGrid items={services} />
<CallToAction href="/contact/" label="Start a project" />
</BaseLayout>
Your component names will differ. Open each one and check its Props interface before passing data. Reused sections keep spacing and typography consistent with the rest of the site.
Step 4: add it to the navigation
Most themes keep menu links in a data file, not in the header markup:
// src/data/navigation.ts
export const NAV = [
{ label: 'Work', href: '/work/' },
{ label: 'Services', href: '/services/' },
{ label: 'About', href: '/about/' },
{ label: 'Contact', href: '/contact/' },
];
Match the theme’s trailing slash style in href. Dropdowns and active-link styling are covered in editing the navigation in an Astro theme. If the project uses @astrojs/sitemap, the new page is added to the sitemap on the next build without any extra step.
Run npm run dev, open the new URL, and check it at mobile width. Adding pages is one step in the wider Astro theme customization guide. Every Komal Astro theme ships reusable sections for this, and the official routing guide covers the full set of routing rules.
FAQ
How do I add a new page in Astro?
Create a .astro or .md file in src/pages/. Its file path becomes the URL, so src/pages/pricing.astro is served at /pricing/.
Why does my new Astro page have no header or styles?
The page isn’t wrapped in the theme’s layout. Import the layout from src/layouts/ and put your content inside it, the same way existing pages do.
How do I add a page to the menu in an Astro theme?
Find the navigation data, usually in src/data/, src/config.ts or the header component, and add an entry with the label and URL. Rebuild and the link appears on every page.