What is the Link component and how does it work?

<Link> from next/link renders a real <a> tag but intercepts clicks to perform client-side navigation, and it prefetches the destination when it enters the viewport. Shared layouts stay mounted, so only the changed part of the page re-renders.

What happens on click

  1. Next.js prevents the full page load.
  2. It uses the prefetched RSC payload if available, otherwise fetches it.
  3. It renders the new segments while keeping parent layouts and their state.
  4. It updates the URL and manages scroll and focus.

Modifier clicks (Cmd/Ctrl+click) and external URLs behave like normal links.

Key props

  • href string or URL object { pathname, query }.
  • replace replace the history entry instead of pushing.
  • scroll set false to keep the scroll position.
  • prefetch "auto"/null (default), true, or false.
  • onNavigate runs only for client-side navigations and can preventDefault(), useful to block leaving a dirty form.
  • transitionTypes (16.2+) passes types to React View Transitions for different animations.
  • Any <a> attribute (className, target, aria-*) passes through.

Related tools

  • useLinkStatus() shows a pending state for the clicked link.
  • usePathname() helps mark the active link.
  • typedRoutes: true type-checks href values.

Interview point

Use <Link> instead of <a> for internal routes; an <a> triggers a full reload and loses client state. Use useRouter only when navigation depends on logic.

Code example

tsx
1// app/components/nav.tsx
2"use client";
3
4import Link from "next/link";
5import { usePathname } from "next/navigation";
6
7const links = [
8 { href: "/", label: "Home" },
9 { href: "/blog", label: "Blog" },
10 { href: "/pricing", label: "Pricing" },
11] as const;
12
13export function Nav() {
14 const pathname = usePathname();
15
16 return (
17 <nav className="flex gap-4">
18 {links.map((l) => (
19 <Link
20 key={l.href}
21 href={l.href}
22 aria-current={pathname === l.href ? "page" : undefined}
23 className={pathname === l.href ? "font-bold" : ""}
24 >
25 {l.label}
26 </Link>
27 ))}
28 <Link href={{ pathname: "/search", query: { q: "nextjs" } }} prefetch={false}>
29 Search
30 </Link>
31 <Link href="https://nextjs.org" target="_blank" rel="noreferrer">Docs</Link>
32 </nav>
33 );
34}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app