Complete the code to import the Next.js navigation hook.
import { [1] } from 'next/navigation';
The usePathname hook is used in Next.js for getting the current path name.
Complete the code to navigate programmatically to the home page.
const router = useRouter();
function goHome() {
router.[1]('/');
}The push method changes the URL and navigates to a new page in Next.js.
Fix the error in this code that prefetches a page for faster navigation.
useEffect(() => {
router.[1]('/about');
}, []);The prefetch method loads the page in the background to speed up navigation.
Fill both blanks to create a link that prefetches and navigates on click.
<Link href="/contact" [1]=[2]>Contact Us</Link>
Setting prefetch=true tells Next.js to load the page in advance for faster navigation.
Fill all three blanks to explain why Next.js navigation is optimized.
Next.js uses [1] to load pages in the background, [2] navigation without full reloads, and [3] caching for faster repeat visits.
Next.js optimizes navigation by prefetching pages, using client-side routing to avoid full reloads, and smart caching to speed up repeat visits.