is a lightweight and customizable React hook and component for implementing breadcrumbs navigation in Next.js applications. It uses `zustand` for state management, persists breadcrumbs in `sessionStorage`, and provides a responsive UI with mobile support.npm install breadcrumbs-nextjs
⚠️ This package has the following peer dependencies that must be installed in your project:
next"^14.0.0 or ^15.0.0",react,react-dom^18.3.1zustandreact-responsive@radix-ui/react-dropdown-menu,@radix-ui/react-slotlucide-react,clsx,tailwind-merge
'use client'
import { useBreadcrumbs } from 'breadcrumbs-nextjs'
export default function Page() {
useBreadcrumbs({
label: 'Dashboard',
path: '/en/dashboard',
})
return <div>Dashboard Page</div>
}label: The text displayed in the breadcrumb UI.path: The full URL path of the page.permission?: (optional) boolean — iffalse, the breadcrumb will not be added.locale?: (optional) locale string for multilingual logic (default is'en').
'use client'
import { Breadcrumbs } from 'breadcrumbs-nextjs'
const Header = () => {
return (
<header>
<Breadcrumbs />
</header>
)
}The component automatically fetches breadcrumbs from the
zustandstore, updates on navigation, persists state insessionStorage, and has a responsive mobile-friendly dropdown.
useBreadcrumbs({
label: string,
path: string,
permission?: boolean,
locale?: string
})Available methods in the store:
breadcrumbs: Breadcrumb[]addBreadcrumb(breadcrumb)removeBreadcrumb(path)removeBreadcrumbsUpTo(path)clearBreadcrumbs()saveBreadcrumbsToSession()previousPathname,setPreviousPathname(path)resetStore()
Breadcrumb =
{ label: string; path: string; }
The package uses react-responsive to adapt breadcrumb display for mobile devices:
- Desktop: full breadcrumb trail.
- Mobile: shows first and last breadcrumb plus a dropdown for intermediate items.
This package uses:
- Radix UI for dropdown menus
- lucide-react for the ellipsis ("...") icon
- Tailwind CSS for styling (must be configured in your project)
- clsx, tailwind-merge for managing classNames
Written in TypeScript and compiled via tsc into the dist/ folder.
Configured with vitest and @testing-library/react.
Run tests with:
npm run test- GitHub: breadcrumbs-react
- Issues: Issue Tracker
MIT