Skip to main content
Decoderen
Browse documentation

Breadcrumbs

Show a page’s position within the site hierarchy.

Current page

Show code
Example.astroAstro
---
import Breadcrumbs from '@/components/navigation/Breadcrumbs.astro';
---

<Breadcrumbs items={[{ label: "Current page", href: "#component-breadcrumbs" }]} />

Nested path

Show code
Example.astroAstro
---
import Breadcrumbs from '@/components/navigation/Breadcrumbs.astro';
---

<Breadcrumbs items={[
  {
    "label": "Decoderen",
    "href": "/decoderen/"
  },
  {
    "label": "Current page",
    "href": "#component-breadcrumbs"
  }
]} />
API reference
items

Type: readonly { label: string; href: string }[]

Default: required

Ancestors followed by the current page. Home is prepended automatically.

class

Type: string | undefined

Default: unset

Adds a class to the component root; keep feature styling scoped.

Slots: None.

Do not supply Home again. PageLayout normally renders these from its crumbs prop.

Original component source
apps/web/src/components/navigation/Breadcrumbs.astroAstro
---
import Icon from '@dhekode/icons/Icon.tsx';
import type { Crumb } from '@/lib/navigation';

/** The last crumb is the current page and is not a link. Home is prepended automatically. */
interface Props {
  class?: string | undefined;
  items: readonly Crumb[];
}

const crumbs: Crumb[] = [{ label: 'Home', href: '/' }, ...Astro.props.items];
---

<nav class:list={['dk-breadcrumbs', Astro.props.class]} aria-label="Breadcrumb">
  <ol role="list">
    {crumbs.map((crumb, index) => {
      const isCurrent = index === crumbs.length - 1;
      return (
        <li>
          {isCurrent ? (
            <span aria-current="page">{crumb.label}</span>
          ) : (
            <>
              <a href={crumb.href}>{crumb.label}</a>
              <Icon name="chevron-right" size={12} />
            </>
          )}
        </li>
      );
    })}
  </ol>
</nav>

<style>
  .dk-breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--dk-space-xs);
    font-family: var(--dk-font-family-sans);
    font-size: var(--dk-font-size-label);
    letter-spacing: 0.02em;
  }

  .dk-breadcrumbs li {
    display: inline-flex;
    align-items: center;
    gap: var(--dk-space-xs);
    color: var(--dk-color-text-tertiary);
  }

  .dk-breadcrumbs a {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--dk-layout-touch-target);
    color: var(--dk-color-text-secondary);
    text-decoration: none;
  }

  .dk-breadcrumbs a:hover {
    color: var(--dk-color-text-primary);
    text-decoration: underline;
  }

  .dk-breadcrumbs [aria-current] {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--dk-layout-touch-target);
    color: var(--dk-color-text-primary);
  }
</style>

Best practices

  • List ancestors followed by the current page.
  • Omit Home from items because the component supplies it.