Dev Helpers
← Back

Route path breadcrumb

Place this file at components/RoutePathBreadcrumb.tsx in an App Router project.

Open this example in the interactive library

Source code

"use client";

// components/RoutePathBreadcrumb.tsx

import Link from "next/link";

import { usePathname } from "next/navigation";

export default function RoutePathBreadcrumb({
  href = "/studio",
  label = "Studio",
}: { href?: string; label?: string } = {}) {
  const parts = usePathname().split("/").filter(Boolean);
  return (
    <nav aria-label="Breadcrumb">
      <Link href="/">Home</Link>
      {parts.map((p, i) => (
        <span key={i}>
          {" "}
          /{" "}
          <Link
            href={"/" + parts.slice(0, i + 1).join("/")}
            aria-current={i === parts.length - 1 ? "page" : undefined}
          >
            {p}
          </Link>
        </span>
      ))}
    </nav>
  );
}