mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
6f4352993d
## 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>
50 lines
1.2 KiB
Plaintext
50 lines
1.2 KiB
Plaintext
---
|
|
title: 'Invalid relative `href` and external `as` values'
|
|
---
|
|
|
|
## Why This Error Occurred
|
|
|
|
Somewhere you are utilizing the `next/link` component, `Router#push`, or `Router#replace` with a relative route in your `href` that has an external `as` value. The `as` value must be relative also or only `href` should be used with an external URL.
|
|
|
|
> **Note**: this error will only show when the `next/link` component is clicked not when only rendered.
|
|
|
|
**Incompatible `href` and `as`**
|
|
|
|
```jsx filename="pages/example.js"
|
|
import Link from 'next/link'
|
|
|
|
export default function Page(props) {
|
|
return (
|
|
<>
|
|
<Link href="/invalid" as="mailto:john@example.com">
|
|
<a>Invalid link</a>
|
|
</Link>
|
|
</>
|
|
)
|
|
}
|
|
```
|
|
|
|
**Compatible `href` and `as`**
|
|
|
|
```jsx filename="pages/example.js"
|
|
import Link from 'next/link'
|
|
|
|
export default function Page(props) {
|
|
return (
|
|
<>
|
|
<Link href="mailto:john@example.com">
|
|
<a>Invalid 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)
|