"use client"; import React from "react"; import { Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, } from "@/components/ui/breadcrumb"; import { ReactNode } from "react"; import { usePathname } from "next/navigation"; import Link from "next/link"; import { Icon } from "./ui/icon"; const SiteBreadcrumb = ({ children }: { children?: ReactNode }) => { const location = usePathname(); const locations = location.split("/").filter((path) => path); return (
{locations.map((link, index) => { let href = `/${locations.slice(0, index + 1).join("/")}`; let itemLink = link; const isLast = index === locations.length - 1; return ( {isLast ? ( itemLink?.replaceAll("-", " ") ) : ( {itemLink?.replaceAll("-", "")} )} {locations.length !== index + 1 && } ); })}
{children}
); }; export default SiteBreadcrumb;