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

Comparison Shouldn't Fail When 'To' Contains a Query String / Search #46

Open
Undistraction opened this issue Jan 11, 2023 · 1 comment

Comments

@Undistraction
Copy link

Undistraction commented Jan 11, 2023

The comparison between window.location.pathname will always fail if the the to contains a query string, for example if the to is: /example/?id=1234#foo, the comparison will be between pathname which is only /example/ and everything before the hash /example/?id=1234, which will fail.

Code here

if (window.location.pathname === withPrefix(anchorPath)) {
@Undistraction Undistraction changed the title Comparison Shouldn't Fail When 'To' Contains a Query Comparison Shouldn't Fail When 'To' Contains a Query String / Search Jan 11, 2023
@Undistraction
Copy link
Author

Undistraction commented Jan 12, 2023

@brohlson would you accept an PR for this. It's a simple fix:

const { pathname, search } = window.location
const pathnameWithSearch = `${pathname}${search}`

if (pathnameWithSearch === withPrefix(anchorPath)) { 
  ...
}

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

1 participant