# <Link> Component

> Instant navigation and background prefetching.

Subject: Next.js | Lesson 20 of 65 | 5 min read
Interactive lesson: https://codewithanimation.in/nextjs/link-component
Previous: [Intercepting Routes (..)](https://codewithanimation.in/nextjs/intercepting-routes.md) | Next: [redirect & permanentRedirect](https://codewithanimation.in/nextjs/redirect-api.md)

## Extending the anchor

The `<Link>` component (imported from `next/link`) is the standard way to navigate in Next.js.

Under the hood, it renders a standard HTML `<a>` tag so that search engines can crawl your site normally. However, it overrides the default browser behavior to prevent full page reloads.

## The SPA illusion

If you use a standard `<a href="/dashboard">`, the browser throws away your entire application state, blanks the screen, and downloads everything from scratch.

The `<Link>` component intercepts the click, performs a 'soft' client-side navigation, and only swaps out the React components that actually changed. This makes your app feel instantly responsive.

## Viewport and hover prefetching

Next.js doesn't wait for the user to click. It predicts the future.

In production, as soon as a `<Link>` scrolls into the viewport, Next.js partially prefetches its data. The moment the user hovers their mouse over the link, Next.js upgrades it to a full prefetch, downloading the destination's RSC payload before the mouse button is even released.

## Common mistake: The development mode trap

A very common point of confusion is testing prefetching locally.

Developers open their network tab, hover over a `<Link>`, and see nothing happen. This is intentional. Next.js completely disables prefetching in development mode. You must run `next build` and `next start` to observe prefetch network requests.

## Tip: Next.js 15 Prefetching Defaults

In Next.js 15, the default `prefetch` behavior was heavily optimized. It no longer prefetches the entire page aggressively.

By default, it only prefetches the layout and loading states. If you want the old, aggressive behavior where the entire page is prefetched instantly, you must explicitly set `<Link href="/about" prefetch={true}>`.

## Try it: The Premonition

Hover your mouse over the link below, but don't click it yet. Watch how Next.js detects your intent and quietly downloads the page in the background before you even click.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/link-component

## Check yourself

### Question 1

Why might you not see network requests when hovering over a <Link> component on your local machine?

- A. You forgot to set prefetch={true}
- B. Prefetching is disabled in development mode
- C. The browser cache is catching the request
- D. You must use the useRouter hook for prefetching

Correct answer: B

Next.js disables prefetching during development (`next dev`) to conserve resources and ensure you are always seeing the latest code changes. It only activates in production (`next start`).

- Why not A: Even without prefetch={true}, hovering triggers a prefetch in production.
- Why not C: While caching plays a role, Next.js explicitly disables the prefetch mechanism in dev.
- Why not D: The <Link> component handles prefetching automatically.

### Question 2

What is the primary architectural difference between <Link href='/'> and <a href='/'> in Next.js?

- A. <Link> does not render an HTML <a> tag in the DOM
- B. <Link> triggers a hard page reload
- C. <Link> performs client-side navigation, preserving React state
- D. <Link> only works for external URLs

Correct answer: C

Standard anchor tags cause the browser to do a full page reload, destroying React state. `<Link>` intercepts the click and performs a soft, client-side React state update.

- Why not A: <Link> definitely renders an <a> tag for accessibility and SEO.
- Why not B: The exact opposite. It triggers a soft navigation.
- Why not D: It is specifically designed for internal routing.

## Remember this

- Always use `<Link>` for internal navigation to preserve the SPA feel.
- Prefetching happens automatically when links enter the viewport (partial) or are hovered (full).
- Prefetching is completely disabled in development mode.
- In Next.js 15, use `prefetch={true}` if you need to aggressively prefetch the entire page.
