Repository navigation
Keep hash link queries before the hash - #579
Open
ivanjohn121523 wants to merge 1 commit into
Open
ivanjohn121523 wants to merge 1 commit into
ivanjohn121523 wants to merge 1 commit into
Conversation
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().
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.hrefsprefixed the whole target with#. A link to/settings?tab=profilerendered 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, becausenavigatesplits 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 shapenavigatealready 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 inuse-hash-location.test.tsxasserts the href and that opening it renders the settings route with searchtab=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.