Skip to main content

Nav

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:

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.