Skip to main content
The <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

string | object
required
The path or URL to navigate to. Accepts a string or a URL object.
boolean
default:"false"
When true, replaces the current history entry instead of pushing a new URL onto the browser history stack.
boolean
default:"true"
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.
boolean | null
default:"null"
Controls prefetching. Prefetching only occurs in production.
  • null or "auto" (default) — prefetches the full route for static routes; prefetches down to the nearest loading.js boundary for dynamic routes
  • true — prefetches the full route for both static and dynamic routes
  • false — disables prefetching on viewport entry and on hover
function
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.
string[]
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
Use usePathname() 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

The same option is available when using router.push():

Blocking navigation for unsaved changes

Use onNavigate 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 using scroll-padding-top:
app/globals.css

Version history