Skip to content

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

Closed

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="/#/about" target="_blank">About</a>

Now the rendered <a> looks like this:

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

Activity

  1. leesb971204 commented on Sep 25, 2025

    @leesb971204
    Contributor

    I think this works fine on the latest version(v1.132.6).

  2. SavKS commented on Sep 25, 2025

    @SavKS

    The same issue occurs on the latest version as well. But it’s not related to the target. When using HashRouter, the Link component does not add the “#” before the path.

  3. dsiguero commented on Sep 25, 2025

    @dsiguero
    Author

    I think this works fine on the latest version(v1.132.6).

    I've updated the reproduction link to use v1.132.6 and it's still not working as expected

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

  4. dsiguero commented on Sep 25, 2025

    @dsiguero
    Author

    The same issue occurs on the latest version as well. But it’s not related to the target. When using HashRouter, the Link component does not add the “#” before the path.

    Yep! that is true, but regular links work fine even without the hash symbol, as the resulting URL gets it anyway.

  5. leesb971204 commented on Sep 26, 2025

    @leesb971204
    Contributor

    I think this works fine on the latest version(v1.132.6).

    I've updated the reproduction link to use v1.132.6 and it's still not working as expected

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

    I realize now that I misunderstood — my apologies.
    I’m not very familiar with hashHistory.
    Could you try applying it with the version of the PR I opened?

  6. dsiguero commented on Sep 26, 2025

    @dsiguero
    Author

    I think this works fine on the latest version(v1.132.6).

    I've updated the reproduction link to use v1.132.6 and it's still not working as expected
    https://stackblitz.com/edit/github-gsxsnwbi?file=src%2Froutes%2F__root.tsx

    I realize now that I misunderstood — my apologies. I’m not very familiar with hashHistory. Could you try applying it with the version of the PR I opened?

    No worries 🙂!

    Your PR seems to in fact fix the issue, now all rendered <a> elements have the hash symbol (#) on their href, and work as expected regardless of whether the target property is present or not.

    Thank you for your work!
    Dan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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