-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Open
Labels
Description
I'm using React Router as a...
library
Reproduction
- Go to https://stackblitz.com/edit/github-bzaopgvp?file=app%2Froutes%2Fhome.tsx
- Inspect the two
Link
s rendered in the Preview panel with the browser's developer tools: they both render ana
element withhref="/"
System Info
System:
OS: Linux 6.11 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
CPU: (22) x64 Intel(R) Core(TM) Ultra 7 165H
Memory: 9.12 GB / 30.78 GB
Container: Yes
Shell: 5.2.21 - /usr/bin/bash
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v22.14.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
bun: 1.2.13 - ~/.nvm/versions/node/v22.14.0/bin/bun
Browsers:
Chrome: 138.0.7204.49
Chromium: 137.0.7151.103
npmPackages:
vite: 6.3.5 => 6.3.5
Used Package Manager
yarn
Expected Behavior
- With
<Link to={{ pathname: '' }}>
, I expect to see rendered<a href="/">
- With
<Link to={{ pathname: undefined }}>
, I expect to see rendered<a>
Rationale: we use the Link
component to be styled as a button, and this button needs to be disabled sometimes. When the button is disabled, we don't want to have any href
attribute at all.
Actual Behavior
Empty string and undefined
are treated in the same way by the Link
component when passed as a pathname
- they both render <a href="/">
.