-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Closed
Labels
Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.Related to Next.js linking (e.g., <Link>) and navigation.
Description
Feature request
I want a more intuitive Link
API which respects expectations we have around native a
tags.
Is your feature request related to a problem? Please describe.
The current link API looks like the following:
<Link href="/about">
<a>here</a>
</Link>
This is problematic for a few reasons:
- It breaks intuition around a11y. When I see an
a
tag without anhref
, alarm bells go off, because that is a UX anti-pattern. In fact, this API makes it impossible to appease theanchor-is-valid
eslint-plugin-jsx-a11y rule (see https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/402). - It requires a call to
cloneElement
which should be avoided as its behavior is confusing. (How would I know mya
tag will be given anhref
? Nothing about this API suggests that.)
Describe the solution you'd like
I would like a solution which doesn't require you to type an a
tag without an href
and also doesn't require you to duplicate the href
information.
Describe alternatives you've considered
There are a few good alternatives:
- Default to
a
tag if no children are given:
<Link href="/about" />
This is the approach react-router uses and it works quite well.
- Use a render prop:
<Link href="/about">
{href => <a href={href}>here</a>}
</Link>
This method appeases the anchor-is-valid
rule and doesn't require the user to duplicate href information since the build href is passed down to the component they are rendering.
- Component injection:
<Link href="/about" component={a} />
A combination of 1 and 2 would be powerful enough to cover all reasonable use cases.
Additional context
trevordmiller, jaydenseric, EvHaus, wallchuck, tsvetan-ganev and 225 more415DomSmith, leanazulyoro, lucascaton, DysphoricDysphoria, ryota-murakami and 5 moreandycochran, Lunnatica, DysphoricDysphoria, ryota-murakami, anuveyatsu and 1 more
Metadata
Metadata
Assignees
Labels
Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.Related to Next.js linking (e.g., <Link>) and navigation.