Skip to content

Commit 822af72

Browse files
committed
Fix active link bug
1 parent 59ff419 commit 822af72

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

frontend/src/app/home/components/navbar/Navbar.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ import Link from "next/link";
33
import Header from "@/components/ui/Header";
44

55
const Navbar = () => {
6-
return (
7-
<nav className="flex justify-between items-center p-4 bg-gray-900">
8-
<div className="flex-shrink-0">
9-
<Header />
10-
</div>
6+
const isActive = (path: string) => window.location.pathname === path;
7+
return (
8+
<nav className="flex justify-between items-center p-4 bg-gray-900">
9+
<div className="flex-shrink-0">
10+
<Header />
11+
</div>
1112

12-
<div className="flex space-x-6">
13-
<Link href="/home" className="text-primary-300">
14-
Home
15-
</Link>
16-
<Link href="" className="text-primary-300 opacity-50 hover:opacity-100">
17-
About Us
18-
</Link>
19-
<Link href="https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g15" className="text-primary-300 opacity-50 hover:opacity-100">
20-
Our Codebase
21-
</Link>
22-
</div>
23-
</nav>
24-
);
13+
<div className="flex space-x-6">
14+
<Link href="/home" className={`text-primary-300 hover:underline ${isActive("/home") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
15+
Home
16+
</Link>
17+
<Link href="" className={`text-primary-300 hover:underline ${isActive("/about") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
18+
About Us
19+
</Link>
20+
<Link href="https://github.com/CS3219-AY2425S1/cs3219-ay2425s1-project-g15" className="text-primary-300 opacity-50 hover:underline hover:opacity-100">
21+
Our Codebase
22+
</Link>
23+
</div>
24+
</nav>
25+
);
2526
};
2627

2728
export default Navbar;

0 commit comments

Comments
 (0)