The Nav component provides the primary site navigation. It displays your site’s brand (a text wordmark by default, or a logo if you pass one), a list of navigation links, and optional search. On viewports narrower than 640px, the links collapse behind a hamburger menu button. The colour-scheme control lives in the footer.
---
import Nav from "astro-theme-university/components/Nav.astro";
---
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
name * | string | --- | Site name — rendered as a text wordmark when no logo is provided, and used as alt text for the logo when one is. |
links | NavLink[] | [] | Navigation links displayed in the top bar. |
search | boolean | true | Whether to show the search button and dialog. |
logo | ImageMetadata | --- | Logo image (light mode). When omitted, the site name renders as a text wordmark instead. |
logoDark | ImageMetadata | --- | Logo image (dark mode). Only used when `logo` is also provided. |
logoCompact | ImageMetadata | --- | Compact logo (e.g. a crest or monogram) swapped in below the mobile breakpoint, where a wide horizontal lockup would wrap the nav bar. Only used when `logo` is also provided; when omitted the full logo is shown at every width. |
logoCompactDark | ImageMetadata | --- | Compact logo (dark mode). Only used when `logoCompact` is provided. |
homeHref | string | --- | Where the logo links (default the site base). |
labels | Partial<ThemeLabels> | --- | Translations of the nav's labels; any left out stay English. |
The NavLink type has the following shape:
interface NavLink {
text: string;
href: string;
}
Usage#
Nav is typically used via BaseLayout rather than directly, but it can be used
standalone if you need a custom layout.
---
import Nav from "astro-theme-university/components/Nav.astro";
---
<Nav
name="My Site"
links={[
{ text: "Home", href: "/" },
{ text: "About", href: "/about/" },
{ text: "Blog", href: "/blog/" },
]}
/>
Behaviour#
The component handles several concerns automatically:
- Active link detection — the current page’s link receives
aria-current="page"based on URL path matching. - Mobile menu — below 640px, links move behind a hamburger toggle button
that updates
aria-expanded. - Search — the optional search button opens a native dialog backed by the site’s Pagefind index; Cmd/Ctrl+K works globally.
- Brand mark — with no
logoprop, the sitenamerenders as a text wordmark (.at-nav-wordmark). When you pass alogo(an importedImageMetadata), it replaces the wordmark; passlogoDarkas well and the nav switches between the two based on the active theme (logoDarkis only used whenlogois also given). - Compact mark — a wide horizontal lockup can wrap the nav bar on narrow
screens. Pass
logoCompact(a crest or monogram) and the nav swaps to it below the 640px breakpoint, restoring the fulllogoabove it;logoCompactDarksupplies a dark-mode variant. Both are only used whenlogois given.
Notes#
A live example is not shown here as it would conflict with this page’s own navigation. See the nav bar at the top of this site for a working instance.