import Link from 'next/link'; export default function Home() { return ( <div> <Link href="/about"> <a>About Us</a> </Link> </div> ); }
The Next.js Link component enables client-side navigation. Clicking the link changes the URL and renders the new page without a full reload, making navigation faster and preserving state.
In Next.js 14+, the Link component no longer requires an inner <a> tag. The href prop is used for the destination URL. Using 'to' or 'url' props is incorrect.
import Link from 'next/link'; export default function Nav() { return ( <nav> <Link href="/blog"> <button>Blog</button> </Link> </nav> ); }
Wrapping a <button> inside Link causes the browser to treat the click as a button action, not a link click. This triggers a full page reload. Link expects an anchor or plain text for client navigation.
import { useState } from 'react'; import Link from 'next/link'; export default function Counter() { const [count, setCount] = useState(0); return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> <Link href="/other">Go to Other</Link> </div> ); }
React state is lost when navigating away and back because the component unmounts and remounts. Next.js does not preserve React state across page navigations by default.
Next.js Link automatically prefetches the code and data for the linked page in the background when the link is visible, speeding up navigation. It does not require manual calls or anchor tags inside.