Skip to content

Keep hash link queries before the hash - #579

Open
ivanjohn121523 wants to merge 1 commit into
molefrog:mainfrom
ivanjohn121523:fix-hash-link-query
Open

ivanjohn121523 wants to merge 1 commit into
molefrog:mainfrom
ivanjohn121523:fix-hash-link-query

Conversation

@ivanjohn121523

@ivanjohn121523 ivanjohn121523 commented Oct 17, 2026 •

Copy link
Copy Markdown

wouter is a small, active React router with TypeScript definitions, a bun test suite, and contribution notes, and it does not require a CLA. That fits a short React and TypeScript behavior fix with a visible before and after.

Hash-routed links that include a query string put that query inside the hash, so opening the link address does not match the route.

Recording
url-parse.zip

useHashLocation.hrefs prefixed the whole target with #. A link to /settings?tab=profile rendered as #/settings?tab=profile. Following that address makes the path /settings?tab=profile, which does not match /settings, and the search string stays empty. A normal click still worked, because navigate splits on ? and writes the query before the hash. Opening the address, copying the link, or using a modifier click follows the href as written.

I changed only the href formatter so the query stays before the hash (?tab=profile#/settings). That is the URL shape navigate already produces and the readme describes. I left route matching and click handling alone, so hash links without a query are unchanged.

Tested with bun test. The new case in use-hash-location.test.tsx asserts the href and that opening it renders the settings route with search tab=profile. The hash-location file passed its 24 tests, and the full suite passed 270 tests with one pre-existing skip. The hash-location module gzips to 497 bytes, under its 1000 byte limit.

Link hrefs for useHashLocation prefixed the whole target with #, so a query
landed inside the fragment. Opening that address made the path
/settings?tab=profile, which does not match /settings. Place the query
before the hash, matching navigate().
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant