Default
default.tsx
const items = [
{ icon: <FaHome />, label: "Home", path: "/" },
{ icon: <FaCompactDisc />, label: "Music", path: "/music" },
{ icon: <FaImage />, label: "Images", path: "/photography" },
{ icon: <FaCode />, label: "Code", path: "/code" },
{ icon: <FaCommentAlt />, label: "Blog", path: "/blog" },
{ icon: <FaPaintBrush />, label: "Design", path: "/design" }
];
const currentPath = "/code/project-one";
const normalizePath = (p: string) =>
p.endsWith("/") && p.length > 1 ? p.slice(0, -1) : p;
const isItemActive = (item) => {
const itemPath = normalizePath(item.path);
const activePath = normalizePath(currentPath);
if (itemPath === "/") {
return activePath === "/";
}
return activePath === itemPath || activePath.startsWith(`${itemPath}/`);
};
<Navbar
items={items}
isItemActive={isItemActive}
theme="primary"
rounding="full"
shadow="light"
/>