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

[Bug]: location.search return blank string when using useLocation and hash # after ? #12334

Closed
linx5867 opened this issue Nov 21, 2024 · 4 comments
Labels

Comments

@linx5867
Copy link

What version of React Router are you using?

react-router-dom 1.23.1

Steps to Reproduce

const location = useLocation();
console.log(location.search);

  1. when url is 'https://issac.test.com/index.html?region=test&wenben=test#/management/content-mgr/test', location.search return ''. looks like a bug. And when using 'new URLSearchParams(location.href)',return ok

  2. when url is 'https://issac.test.com/index.html#/management/content-mgr/test?region=test&wenben=test', location.search return '?region=test&wenben=test'. looks OK

Expected Behavior

the return value is not balnk as normal, no matter the order of # an ?

Actual Behavior

when url is 'https://issac.test.com/index.html?region=test&wenben=test#/management/content-mgr/test', location.search return ''. looks like a bug. And when using 'new URLSearchParams(location.href)',return ok

@linx5867 linx5867 added the bug label Nov 21, 2024
@linx5867
Copy link
Author

useSearchParams has the same issue, maybe it depends on useLocation

@timdorr
Copy link
Member

timdorr commented Nov 21, 2024

Are you using HashRouter? Also, 1.23.1 is not a valid version for that library.

@linx5867
Copy link
Author

@timdorr Yes, we'r using HashRouter. BTW, to avoid error occurring, which version should we update to?

@timdorr
Copy link
Member

timdorr commented Nov 22, 2024

I just meant it looks like a typo. V1 is over a decade old, so I assume that's not what you're using.

In this case, this is expected behavior for that kind of router. It has to encode the query string into the hash so it can adjust it without reloading the page. If you switch to another router type, it will behave as expected.

@timdorr timdorr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants