Skip to content

Commit e559a2d

Browse files
committed
Fix window undefined error in navbar
1 parent efd7777 commit e559a2d

File tree

1 file changed

+10
-3
lines changed
  • frontend/src/app/(home)/components/navbar

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22
import Link from "next/link";
33
import Header from "@/components/ui/Header";
44

55
const Navbar = () => {
6-
const isActive = (path: string) => window.location.pathname === path;
6+
const [currentPath, setCurrentPath] = useState("");
7+
8+
useEffect(() => {
9+
// Update the state with the current pathname on the client side
10+
setCurrentPath(window.location.pathname);
11+
}, []);
12+
13+
const isActive = (path: string) => currentPath === path;
714
return (
815
<nav className="flex justify-between items-center p-4 bg-gray-900">
916
<div className="flex-shrink-0">
1017
<Header />
1118
</div>
1219

1320
<div className="flex space-x-6">
14-
<Link href="/home" className={`text-primary-300 hover:underline ${isActive("/") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
21+
<Link href="/" className={`text-primary-300 hover:underline ${isActive("/") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>
1522
Home
1623
</Link>
1724
<Link href="" className={`text-primary-300 hover:underline ${isActive("/about") ? "opacity-100" : "opacity-50 hover:opacity-100"}`}>

0 commit comments

Comments
 (0)