forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update error when internal href and external as are used (vercel#20658)
* Update error when internal href and external as are used * Update to handle error outside invariant * Update err.sh components
- Loading branch information
Showing
7 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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 | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<Link href="/invalid" as="mailto:[email protected]"> | ||
<a>Invalid link</a> | ||
</Link> | ||
</> | ||
) | ||
} | ||
``` | ||
|
||
**Compatible `href` and `as`** | ||
|
||
```jsx | ||
import Link from 'next/link' | ||
|
||
export default function Page(props) { | ||
return ( | ||
<> | ||
<Link href="mailto:[email protected]"> | ||
<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](https://nextjs.org/docs/routing/introduction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<Link href="/second" as="mailto:[email protected]"> | ||
<a id="click-me">email</a> | ||
</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters