Dev Helpers
← Back

Exact active route link

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

Open this example in the interactive library

Source code

"use client";

// components/ExactActiveRouteLink.tsx

import Link from "next/link";

import { usePathname } from "next/navigation";

export default function ExactActiveRouteLink({
  href = "/studio",
  label = "Studio",
}: { href?: string; label?: string } = {}) {
  const path = usePathname();
  return (
    <Link href={href} aria-current={path === href ? "page" : undefined}>
      {label}
    </Link>
  );
}