<Link> component extends the HTML <a> element to provide prefetching and client-side navigation between routes. It is the primary way to navigate in Next.js.
app/page.js
Props
The path or URL to navigate to. Accepts a string or a URL object.
When
true, replaces the current history entry instead of pushing a new URL onto the browser history stack.Controls scroll behavior on navigation. When
true, Next.js maintains scroll position if the page is visible in the viewport, or scrolls to the top of the first page element if not.Set to false to disable this behavior entirely.Controls prefetching. Prefetching only occurs in production.
nullor"auto"(default) — prefetches the full route for static routes; prefetches down to the nearestloading.jsboundary for dynamic routestrue— prefetches the full route for both static and dynamic routesfalse— disables prefetching on viewport entry and on hover
Called during client-side navigation. The event object includes
preventDefault() to cancel the navigation.onNavigate differs from onClick: it only fires during SPA navigation, not for modifier-key clicks, external URLs, or links with the download attribute.A list of transition type strings passed to
React.addTransitionType during navigation. Enables <ViewTransition> components to apply animations based on the navigation type.Standard
<a> attributes such as className, target, and rel are passed through to the underlying <a> element.Examples
Linking to dynamic segments
Use template literals to generate links to dynamic routes.app/blog/post-list.js
Active link detection
UseusePathname() to highlight the active link. Because usePathname is a client hook, extract nav links into a Client Component.
app/ui/nav-links.js
Scrolling to a hash
Append a# hash to the href to scroll to a specific element on the destination page.
Replacing instead of pushing history
Disabling scroll to top
router.push():
Blocking navigation for unsaved changes
UseonNavigate with React Context to block navigation when a form has unsaved changes.
app/components/custom-link.js
Scroll offset with sticky headers
Next.js skips fixed and sticky elements when scrolling to a target. Compensate usingscroll-padding-top:
app/globals.css
Version history
| Version | Changes |
|---|---|
v15.4.0 | "auto" added as alias for default prefetch behavior |
v15.3.0 | onNavigate prop added |
v13.0.0 | Child <a> tag no longer required |
v10.0.0 | href for dynamic routes auto-resolved; as prop no longer needed |
v1.0.0 | next/link introduced |
