Files
vercel__next.js/errors/href-interpolation-failed.mdx
Jam Balaya 6f4352993d docs: add and unify notes to error pages (#72838)
## Description
Unify the note format according to the [contribution
guide](https://nextjs.org/docs/community/contribution-guide#notes).
In addition, add missing bullet points to useful links.

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

---------

Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
2024-11-19 09:44:42 +00:00

57 lines
1.4 KiB
Plaintext

---
title: '`href` Interpolation Failed'
---
## Why This Error Occurred
Somewhere you are utilizing the `next/link` component, `Router#push`, or `Router#replace` with `href` interpolation to build dynamic routes but did not provide all of the needed dynamic route params to properly interpolate the `href`.
> **Note**: this error will only show when the `next/link` component is clicked not when only rendered.
**Invalid `href` interpolation**
```jsx filename="blog-link.js"
import Link from 'next/link'
export default function BlogLink() {
return (
<Link
href={{
pathname: '/blog/[post]/[comment]',
query: { post: 'post-1' },
}}
>
<a>Invalid link</a>
</Link>
)
}
```
**Valid `href` interpolation**
```jsx filename="blog-link.js"
import Link from 'next/link'
export default function BlogLink() {
return (
<Link
href={{
pathname: '/blog/[post]/[comment]',
query: { post: 'post-1', comment: 'comment-1' },
}}
>
<a>Valid link</a>
</Link>
)
}
```
## Possible Ways to Fix It
Look for any usage of the `next/link` component, `Router#push`, or `Router#replace` and make sure that the provided `href` has all needed dynamic params in the query.
## Useful Links
- [Routing section in Documentation](/docs/pages/building-your-application/routing)
- [Dynamic routing section in Documentation](/docs/pages/building-your-application/routing/dynamic-routes)