Programmatic navigation belongs in an interactive client boundary. Use a normal link when the destination is already known and no event logic is required.
Worked example
"use client";
// components/ProgrammaticLibraryNavigation.tsx
import { useRouter } from "next/navigation";
export default function ProgrammaticLibraryNavigation({
destination = "/library",
}: { destination?: string } = {}) {
const router = useRouter();
return <button onClick={() => router.push(destination)}>Open library</button>;
}Implementation notes
Validate any destination assembled from user input before navigation. An internal route helper should only construct supported same-site paths.
Try it yourself
Test keyboard activation and back navigation after the route change.
Open the Next.js example →Editorial date August 9, 2025 · Published December 6, 2026