Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using hash history, a slash is added to the href when changing window.location.hash and search params before the hash get added to href #3739

Open
JamesHyot opened this issue Mar 11, 2025 · 1 comment

Comments

@JamesHyot
Copy link

Which project does this relate to?

Router

Describe the bug

PR #3644 for issue #3595 introduced two breaking changes in v1.112.8 :

  • an additional slash is added in some cases
  • search params are mixed between "server search params" and "hash search params"

I have to agree with the opinion of Tanner in #1449, maybe this breaking change should not have been introduced.
I think the additional slash can be safely removed, and maybe the new search behaviour can be an option ?

I'll try and create a PR for this if that's OK

Your Example Website or App

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

Steps to Reproduce the Bug or Issue

  1. Go to About
  2. Navigate to Other using the yellow or orange links
  3. See that the href displayed is //other instead of /other (also the header link is not "active")
  4. If you add a search param in the preview url (for instance https://wmaibpqbzggithub-fcsj--3000--495c5120.local-corp.webcontainer.io/**?toto=tutu**#/about), navigating using window.location.hash or tags results in an href value of //other?toto=tutu

Expected behavior

The previous behaviour was that when using window.location.hash = '#/about' or a regular , the href would have only one /.

Also the search params sent to the server (before the # character) are now received by the router and are not separate from the "search params" that come after the # character. I do have a use case in my application where I use regular search params so that the server can dynamically change the source of my SPA script, and "hash search params" so that my @tanstack/react-router routes can use them for navigation. I do agree it is a pretty uncommon use case

Screenshots or Videos

No response

Platform

  • OS: [Windows]
  • Browser: [Edge, Firefox]
  • Version: [Edge 134.0.3124.51, Firefox 136.0]

I don't think the issue is platform specific

Additional context

No response

@schiller-manuel
Copy link
Contributor

schiller-manuel commented Mar 11, 2025

if its feasible to make this opt in, then we can add an option. otherwise we will just revert that PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants