Skip to content

Commit 14148b9

Browse files
committed
feat: Adding active page indicator in Navbar
1 parent e8f3bfe commit 14148b9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/main-nav.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { cn } from "@/lib/utils";
66
import { NavItem } from "@/types/nav";
77
import Image from "next/image";
88
import Link from "next/link";
9-
import { useEffect, useRef, useState } from "react";
9+
import { usePathname } from 'next/navigation';
10+
import { useEffect,useRef,useState } from "react";
1011
import { BiMenuAltRight } from "react-icons/bi";
1112
import { MdOutlineClose } from "react-icons/md";
1213
import { ThemeToggle } from "./theme-toggle";
@@ -19,6 +20,7 @@ interface MainNavProps {
1920
export function MainNav({ items }: MainNavProps) {
2021
const [toggle, setToggle] = useState<boolean>(false);
2122
const menuRef = useRef<HTMLDivElement>(null);
23+
const pathname = usePathname();
2224

2325
useEffect(() => {
2426
if (!toggle) return;
@@ -77,7 +79,8 @@ export function MainNav({ items }: MainNavProps) {
7779
href={item.href}
7880
className={cn(
7981
"flex items-center whitespace-nowrap text-xl font-semibold sm:text-sm",
80-
item.disabled && "cursor-not-allowed opacity-80"
82+
item.disabled && "cursor-not-allowed opacity-80",
83+
(item.href === pathname) && "text-purple-600"
8184
)}
8285
>
8386
{item.title}

0 commit comments

Comments
 (0)