Files
vercel__next.js/errors/link-passhref.mdx
Hendrik Liebau 4b66771895 Remove deprecated legacyBehavior and passHref prop from Link component (#83003)
The `legacyBehavior` prop of the `Link` component has been deprecated
since #77473. For Next.js 16, we're finally removing support for it.
Consequently, we're also removing support for the `passHref` prop, which
was only useful in conjunction with the `legacyBehavior` prop.

A [codemod is
available](https://nextjs.org/docs/app/guides/upgrading/codemods#new-link)
to help you automatically upgrade your codebase.

reverts #77473

---------

Co-authored-by: Sebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>
2025-08-26 14:04:27 +02:00

35 lines
869 B
Plaintext

---
title: 'Link `passHref`'
---
> **Note**: Starting with version `16`, Next.js does not support the `passHref` and `legacyBehavior` props for a `Link` component anymore.
> Ensure `passHref` is used with custom `Link` components.
## Why This Error Occurred
`passHref` was not used for a `Link` component that wraps a custom component. This is needed in order to pass the `href` to the child `<a>` tag.
## Possible Ways to Fix It
If you're using a custom component that wraps an `<a>` tag, make sure to add `passHref` and `legacyBehavior`:
```jsx filename="nav-link.js"
import Link from 'next/link'
import styled from 'styled-components'
const StyledLink = styled.a`
color: red;
`
function NavLink({ href, name }) {
return (
<Link href={href} passHref legacyBehavior>
<StyledLink>{name}</StyledLink>
</Link>
)
}
export default NavLink
```