Skip to content

Link with undefined pathname should omit href attribute from a element #13884

@lorumic

Description

@lorumic

I'm using React Router as a...

library

Reproduction

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="/">.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions