Files
vercel__next.js/errors/incompatible-href-as.mdx
T
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

51 lines
1.3 KiB
Plaintext

---
title: 'Incompatible `href` and `as` values'
---
## Why This Error Occurred
Somewhere you are utilizing the `next/link` component, `Router#push`, or `Router#replace` with a dynamic route in your `href` that has an incompatible `as` value. The `as` value is incompatible when the path doesn't provide only the expected parameters for the dynamic route.
> **Note**: this error will only show when the `next/link` component is clicked not when only rendered.
**Incompatible `href` and `as`**
```jsx filename="pages/blog.js"
import Link from 'next/link'
export default function Page(props) {
return (
<>
<Link href="/[post]" as="/post-1/comments">
<a>Invalid link</a>
</Link>
</>
)
}
```
**Compatible `href` and `as`**
```jsx filename="pages/blog.js"
import Link from 'next/link'
export default function Page(props) {
return (
<>
<Link href="/[post]" as="/post-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` and `as` values are compatible
## 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)