Add ability to pass in custom getLocation 🥳 #239
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.
Problem
Issue #152 shows that a few application authors were wanting to automatically parse the search property. This way they don't need to implement the parse logic on their end. Some suggested to wrap the history with the own implementation so it would also handle outgoing navigation.
Reach Router with good reason does not handle this because there are so many query parsing libraries out there and not bundling this in it keeps this package small.
Possible Solution
To help application authors who want to parse the search property into their own query object, Reach Router could allow them to pass in a custom
getLocation
into the options.Downsides
This will require users to duplicate the mapping of the source object like you have in the history file. I considered still using the "private"
getLocation
as the default, but was concerned that some users wouldn't want any default logic and they would apply that themselves.Changes
Made options argument a object with a default value
I noticed options is not currently used so I made it an object and used default values for the getLocation. The benefit of this approach is it pushes the responsibility of parsing the search property to the author and adds very little overhead to the package.
Add tests
I noticed history didn't have any tests, so I added a few for this change. Happy to add more if needed, it seemed most of the logic was already tested in the index.test file.
Add documentation
For now I just updated the documentation for the createHistory page. Happy to add examples.