-
Notifications
You must be signed in to change notification settings - Fork 961
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
Add history.navigate API #472
Conversation
@@ -59,3 +59,8 @@ export const locationsAreEqual = (a, b) => | |||
a.hash === b.hash && | |||
a.key === b.key && | |||
valueEqual(a.state, b.state) | |||
|
|||
export const locationPathsAreEqual = (a, b) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names are hard 🤷♂️
Closing this since it is stale. I ended up writing my own history-esque package (inspired by this and the history from |
I recognize a lot of this code :D https://github.com/vuejs/vue-router/blob/dev/src/history/hash.js |
@pshrmn Do you have a link to your work? I'd like to check it out. Thanks 💕 |
https://github.com/pshrmn/hickory (an amalgamation of history and curi) Most everything should be familiar to you. I changed some property names, but the but API is nearly the same. Biggest differences are that I use a different blocking system, I went HTML5 only, and (the main reason that I wrote a new package) I switched to It actually mostly works with React Router if you assign some property names that RR expects. https://codesandbox.io/s/gpg6lLo6 I wouldn't recommend that to anybody, just tested it out of curiosity. Anyways, I'd be happy to give insight if you have any questions. |
This is a proof of concept related to #470. This PR adds a
navigate
method to each history type.This is inspired by the WHATWG browser spec
The basic chain of specs I used to find this started with the
<a>
spec, which leads to the description of how to follow hyperlinks, which in turn leads to the description of how browsers should navigate.history.navigate(path, state)
The
navigate
method has the same argument signature aspush
andreplace
.When
history.navigate
is called, it creates a location object and compares it to the current location object. The only fields that are compared are:pathname
,search
, andhash
(essentially comparing the serialized version of each location).If the next location and the current location are the same, then a
REPLACE
action will occur. If they are different, then aPUSH
action will happen (the actual implementation varies by history type).Implementation
I added
createPushCallback
andcreateReplaceCallback
functions inside each of the history types. These return the callback functions that were being passed totransitionManager.confirmTransitionTo
. This approach was a lot easier than trying to play Frankenstein and putting together a monster of a callback inside ofnavigate
.push
andreplace
always use their respective functions.navigate
determines which one to use based on if the next location is the same as the current location.History Dependents (specifically, React Router)
With React Router, this would allow the
<Link>
to usenavigate
instead ofpush
. Then, the rendered<a>
will have the same behavior as a regular<a>
. Potentially apush
prop would need to be added to<Link>
so that if a user really wants topush
the same location, they could, but I'm not sure why that would be.