Complete the code to import the hook used for active link detection in Next.js.
import { [1] } from 'next/navigation';
The usePathname hook from next/navigation returns the current path, which helps detect active links.
Complete the code to get the current path inside a functional component.
const currentPath = [1]();Calling usePathname() inside a component returns the current URL path as a string.
Fix the error in the code to correctly check if the link is active.
const isActive = currentPath [1] href;= which assigns instead of compares=> by mistakeUse the strict equality operator === to compare currentPath and href for active link detection.
Fill both blanks to create a style object that applies a bold font weight when the link is active.
const linkStyle = { fontWeight: [1] ? 'bold' : [2] };The style sets fontWeight to 'bold' if isActive is true, otherwise 'normal'.
Fill all three blanks to complete the component that renders a navigation link with active styling.
import Link from 'next/link'; import { [1] } from 'next/navigation'; export default function NavLink({ href, children }) { const currentPath = [2](); const isActive = currentPath === href; return ( <Link href={href} style={{ fontWeight: [3] ? 'bold' : 'normal' }} aria-current={isActive ? 'page' : undefined}> {children} </Link> ); }
The component imports usePathname to get the current path, calls it to get currentPath, and uses isActive to conditionally style the link.