In most Astro themes, navigation is a single array of { label, href } objects, kept in a data file such as src/data/navigation.ts or at the top of src/components/Header.astro. Edit that array to add, rename, reorder or remove menu items; the desktop menu, the mobile menu and often the footer all read from it.
Key Takeaways
- Search for an existing menu label to find the navigation array in seconds.
- Change links in the array, not in the header markup, so desktop and mobile stay in sync.
- Use root-relative URLs with the same trailing slash style as the rest of the site.
- Mark the current page with
aria-current="page"usingAstro.url.pathname.- Removing a menu item does not remove the page; delete or redirect it separately.
Find the navigation array
Open the project and search for a label you can see in the menu:
# Terminal
grep -rn "'Pricing'" src/
You will usually land in one of three places: a data file (src/data/navigation.ts, src/data/site.ts), a theme config (src/config.ts, src/site.config.ts), or a constant at the top of the header component. A typical data file looks like this:
// src/data/navigation.ts
export interface NavItem {
label: string;
href: string;
children?: NavItem[];
}
export const NAV: NavItem[] = [
{ label: 'Work', href: '/work/' },
{ label: 'Services', href: '/services/' },
{ label: 'Journal', href: '/journal/' },
{ label: 'Contact', href: '/contact/' },
];
Add, remove or reorder items
Edit the array. Order in the array is order in the menu:
// src/data/navigation.ts
export const NAV: NavItem[] = [
{ label: 'Services', href: '/services/' },
{ label: 'Case studies', href: '/work/' },
{ label: 'About', href: '/about/' },
{ label: 'Contact', href: '/contact/' },
];
Two rules keep links healthy. Use root-relative paths (/about/, not about or the full domain), and match the site’s trailingSlash setting so links do not trigger an extra redirect; the trailing slash tip explains the options. A new item needs a page behind it: see the pages and routing docs if /about/ does not exist yet.
For external links, add a flag and render target="_blank" with rel="noopener" only for those, so readers know they are leaving.
Mark the active page
If the theme does not highlight the current page, add it in the header. Astro.url.pathname is the path of the page being rendered:
---
// src/components/Header.astro
import { NAV } from '../data/navigation';
const path = Astro.url.pathname;
const isActive = (href: string) =>
href === '/' ? path === '/' : path.startsWith(href);
---
<nav aria-label="Main">
<ul>
{NAV.map((item) => (
<li>
<a href={item.href} aria-current={isActive(item.href) ? 'page' : undefined}>
{item.label}
</a>
</li>
))}
</ul>
</nav>
<style>
a[aria-current='page'] {
font-weight: 600;
text-decoration: underline;
}
</style>
Styling on aria-current instead of an active class gives screen reader users the same information sighted users get. The startsWith check keeps “Journal” highlighted on /journal/some-post/.
Add a dropdown
If the NavItem type has children, add a nested array. If the theme’s header does not support dropdowns, a native <details> element works without JavaScript:
---
// src/components/NavItem.astro
import type { NavItem } from '../data/navigation';
interface Props { item: NavItem }
const { item } = Astro.props;
---
{item.children ? (
<details>
<summary>{item.label}</summary>
<ul>
{item.children.map((child) => <li><a href={child.href}>{child.label}</a></li>)}
</ul>
</details>
) : (
<a href={item.href}>{item.label}</a>
)}
Keep dropdowns short. If a menu needs more than seven top-level items, the site structure probably needs work more than the header does. For the small-screen version, the mobile nav component guide builds an accessible toggle.
Keep footer and mobile menus in sync
Check whether the footer imports the same array or has its own list. If it has its own, either import NAV there too or create a separate FOOTER_NAV export in the same file, so every link lives in one place. Then search the project for the old URL to catch hard-coded links in buttons and body copy.
When a theme centralises links like this, rebranding is quick. Every Komal theme is a normal Astro project, so you can restructure navigation any way you like; you can browse Astro themes to see how each one lays out its header in the live preview.
FAQ
Where is the navigation in an Astro theme?
Usually in a data or config file under src/ (for example src/data/navigation.ts or src/config.ts) or at the top of src/components/Header.astro. Search the project for a visible menu label to find it.
How do I add a page to the Astro navigation menu?
Create the page in src/pages/, then add an object with its label and href to the navigation array. The header renders every item in the array, so the link appears on all pages.
Why does my Astro menu link show a 404?
The href does not match a real route. Check the file exists in src/pages/, that the path is root-relative, and that the trailing slash matches your trailingSlash setting.
How do I highlight the current page in Astro navigation?
Compare each link’s href with Astro.url.pathname in the header component and set aria-current="page" on the match, then style that attribute.