Replies: 4 comments
-
Agreed. I think it's good for to match the spec for tags, and allow optional href, |
Beta Was this translation helpful? Give feedback.
0 replies
-
+1, disabling a link shouldn't be that difficult 😩 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Support this idea! |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With the recent
<Link>
behavior rework PR to always make<Link>
produce an<a>
element, I would like to recommend an additional backwards-compatible change to the<Link>
component: make thehref
property optional. Anchor elements without ahref
attribute are valid according to specification:(In terms of browser behavior,
<a>
elements withouthref
are not focusable, so they are basically "disabled links".)There are many situations where you may want to use conditional links, eg. disabling the current page in a breadcrumb navigation, and right now dealing with such conditional links with the
<Link>
component is a pain because of the requiredhref
property, leading one to write code along the lines of this:While you could certainly define the content separately and conditionally wrap it at the end, ultimately it's all extra busywork than if you were simply able to write code like this:
To date, I have been carrying a custom
<Link>
component across my Next.js project that wrapsnext/link
with two major changes: making it always produce an<a>
element as well as making thehref
property optional. With the<Link>
behavior rework PR accounting for the first one, it would be nice if Next.js adopted the second one too so that I could retire my custom<Link>
wrapper entirely in favor of the regularnext/link
.Beta Was this translation helpful? Give feedback.
All reactions