Dev Helpers
← Back

Prefetch on intent

Place this file at components/PrefetchOnIntent.tsx in an App Router project.

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>
  );
}