Complete the code to enable automatic route prefetching in a Next.js Link component.
import Link from 'next/link'; export default function Home() { return ( <Link href="/about" [1]> Go to About </Link> ); }
The prefetch prop on Next.js Link enables automatic prefetching of the linked page in the background.
Complete the code to disable route prefetching for a Next.js Link component.
<Link href="/contact" [1]={false}> Contact Us </Link>
Setting prefetch={false} disables automatic prefetching for the link.
Fix the error in this code that tries to prefetch a route manually using Next.js router.
import { useRouter } from 'next/router'; export default function Page() { const router = useRouter(); function prefetchPage() { router.[1]('/dashboard'); } return <button onClick={prefetchPage}>Prefetch Dashboard</button>; }
The Next.js router has a prefetch method to manually prefetch a route.
Fill both blanks to explicitly enable route prefetching in a Next.js Link component.
<Link href="/profile" [1]=[2]> Profile </Link>
Setting prefetch={true} explicitly enables automatic prefetching of the linked page in the background.
Fill all three blanks to manually prefetch a route on component mount using useEffect and Next.js router.
import { useEffect } from 'react'; import { useRouter } from 'next/router'; export default function DashboardPrefetch() { const router = useRouter(); useEffect(() => { router.[1]([2]); }, [[3]]); return <p>Prefetching dashboard...</p>; }
Use router.prefetch('/dashboard') inside useEffect with router as dependency to prefetch on mount.