Open this example in the interactive library
Live preview
Source code
// components/PreviousAndNextNavigation.tsx
export default function PreviousAndNextNavigation({
links = [
{ label: "Guide", href: "/guide" },
{ label: "About", href: "/about" },
],
current = "/guide",
}: { links?: { label: string; href: string }[]; current?: string } = {}) {
const i = links.findIndex((l) => l.href === current);
return (
<nav aria-label="Adjacent pages">
{i > 0 && (
<a rel="prev" href={links[i - 1].href}>
← {links[i - 1].label}
</a>
)}{" "}
{i >= 0 && i + 1 < links.length && (
<a rel="next" href={links[i + 1].href}>
{links[i + 1].label} →
</a>
)}
</nav>
);
}
