Open this example in the interactive library
Source code
"use client";
// components/PrefetchOnIntent.tsx
import { useRouter } from "next/navigation";
export default function PrefetchOnIntent({
destination = "/library",
}: { destination?: string } = {}) {
const router = useRouter();
return (
<button
onFocus={() => router.prefetch(destination)}
onMouseEnter={() => router.prefetch(destination)}
onClick={() => router.push(destination)}
>
Continue
</button>
);
}
