From 0c5d360c52eeb864340c249b0f913d8983fe95fd Mon Sep 17 00:00:00 2001 From: Clumsy-Coder <19594044+Clumsy-Coder@users.noreply.github.com> Date: Tue, 2 Jan 2024 16:17:35 -0700 Subject: [PATCH] feat(components:navbar): highlight active links ## what - highlight active links ## how - use css classname from `globals.css` - nav-link - highlight link on hover - active-nav-link - highlight link when link href is the same as the url pathname ## why ## where - ./src/components/navbar.tsx ## usage --- src/components/navbar.tsx | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/navbar.tsx b/src/components/navbar.tsx index 43584c5..a1d6941 100644 --- a/src/components/navbar.tsx +++ b/src/components/navbar.tsx @@ -1,4 +1,7 @@ +"use client"; + import Link from "next/link"; +import { usePathname } from "next/navigation"; import { cn } from "@/lib/utils"; import { ModeToggle } from "@/components/darkmode-toggle"; @@ -9,6 +12,8 @@ const links = [ ]; const Navbar = ({ className, ...props }: React.HTMLAttributes) => { + const pathname = usePathname(); + return (