Navbar for next 13.5
Answered
Blood cockle posted this in #help-forum
Blood cockleOP
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
<a className={function} children=...>
How do I I add a navbar the right way?
<a className={function} children=...>
How do I I add a navbar the right way?
Answered by ReverseGem7
'use client'
import { usePathname } from 'next/navigation'
export default function ExampleClientComponent() {
const pathname = usePathname()
}
className={pathname==='/projects' ? 'text-blue-600' : 'text-black'}
6 Replies
Blood cockleOP
Layout.js
import { Inter } from "next/font/google";
import "./globals.css";
import NavBar from "./components/NavBar";
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{" "}
<NavBar />
{children}
</body>
</html>
);
}
@Blood cockle Show navbar Code and function code
Blood cockleOP
This is my NavBar component :
// Assuming you have imported Link from next/link
import Link from "next/link";
export default function NavBar() {
return (
<header className="header">
<Link href="/">
<a>
<div alt="logo" className="w-18 h-18 object-contain">
<svg
</svg>
</div>
</a>
</Link>
<nav className="flex text-lg gap-7 font-medium">
<Link href="/about">
<a
className={({ pathname }) =>
pathname === "/about" ? "text-blue-600" : "text-black"
}
>
About
</a>
</Link>
<Link href="/projects">
<a
className={({ pathname }) =>
pathname === "/projects" ? "text-blue-600" : "text-black"
}
>
Projects
</a>
</Link>
</nav>
</header>
);
}
'use client'
import { usePathname } from 'next/navigation'
export default function ExampleClientComponent() {
const pathname = usePathname()
}
className={pathname==='/projects' ? 'text-blue-600' : 'text-black'}
Answer
Blood cockleOP
Thank you it is resolved