Skip to content

<Link target="_blank"> broken with hash history #5209

@dsiguero

Description

@dsiguero

Which project does this relate to?

Router

Describe the bug

Hi 👋,

After upgrading to the latest TanStack Router (v1.132.2), I noticed that <Link> elements using target="_blank" no longer work correctly when using hash history.

Previously, the rendered <a> looked like this:

<a href="https://github.com/#/about" target="_blank">About</a>

Now the rendered <a> looks like this:

<a href="https://github.com/about" target="_blank">About</a>

This means opening the link in a new tab results in the URL:

http://localhost:5173/about

instead of the expected:

http://localhost:5173/#/about

So the hash is missing in the final URL when target="_blank" is used, breaking navigation in hash-history mode.


Expected behavior:

The <Link> should render with the hash prefix (/#/about) so that opening it in a new tab lands on the correct route in hash-history mode.

Actual behavior:

The <Link> renders as /about, causing the browser to open the wrong URL without the hash.

Your Example Website or App

https://stackblitz.com/edit/github-gsxsnwbi?file=src%2Froutes%2F__root.tsx

Steps to Reproduce the Bug or Issue

  1. Click on About (target _blank).
  2. It opens a new tab with the following URL: <baseURL>/about instead of <baseURL>/#/about

Expected behavior

The <Link> should render with the hash prefix (/#/about) so that opening it in a new tab lands on the correct route in hash-history mode.

Screenshots or Videos

No response

Platform

  • Router Version: v1.131.2
  • History mode: createHashHistory()
  • OS: macOS/Linux
  • Browser: Chrome
  • Browser Version: v138
  • Bundler: vite
  • Bundler Version: v7.1.7

Additional context

This only happens when using target="_blank". Links without target navigate correctly within the same tab.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions