react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Bug]: useSearchParams hook ignores search params if url ends with hash-link

Open segnord opened this issue 1 year ago • 0 comments

What version of React Router are you using?

6.17.0

Steps to Reproduce

Consider url http://localhost:3000/?location=xx&room=yy#/view

The hook can't see parameters when the broser api url.searchParams can parse them.

note: everything is ok for http://localhost:3000/#/view?location=xx&room=yy

Expected Behavior

http://localhost:3000/?location=xx&room=yy#/view

const [searchParams] = useSearchParams();
console.log(searchParams.has("room"))
// returns TRUE

const url = new URL(window.location.href);
console.log(url.searchParams.has("room"))
// returns TRUE

Actual Behavior

http://localhost:3000/?location=xx&room=yy#/view

const [searchParams] = useSearchParams();
console.log(searchParams.has("room"))
// returns FALSE

const url = new URL(window.location.href);
console.log(url.searchParams.has("room"))
// returns TRUE

segnord avatar Mar 13 '24 13:03 segnord