-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
New history event proposal #5562
Comments
Looking at both popstate and hashchange event interfaces for inspiration, I was thinking that it may be useful to have the
I'm not entirely sure the |
actually, now that I've looked at it, I think it would be great to have the There appears to be lots of people that want to ignore hash changes in the For example: user is on |
A couple questions I'm thinking through with this:
|
One additional thing that would be useful to know is whether the navigation is a pop (going back a page in history), a replace (overwriting the current page in history), or a push (adding a new page to history). It's currently impossible to accurately detect this sort of thing using |
My naive first impression is yes - it should fire when popstate fires. And then with oldURL / newURL you can just bail early if you don't need to do anything?
Interesting. But it may be a barrier to getting this proposal being adopted if we do co-opt it. Perhaps if an additional proposal could work out the issues with the previously blocked proposal, then we could add additional info to the event at that time or something? |
Small update: I changed the proposed event name to potentially be I don't have all the context for why |
I agree - this would be a nice additional property to add to the |
I'm still somewhat hesitant about this - I think it should be resolved in its own proposal, and then once accepted we can simply add that detail to the event we fire. It seems like a good way of ensuring this proposal doesn't get blocked on issues that may come up with adding that information. (An addition thought on that as well: what would that detail be if you do |
If it causes complications, we could remove it? I am not seeing how it would add complications.
My understanding is that this is a |
Hey folks! I've been aware of the issues with history for a while, but toward the end of last year fixing them became one of my major projects at work. The conclusion I and others at Google came to over the last month or so is that the the problem goes deeper than just the Our initial proposal for fixing this is at https://github.com/slightlyoff/history_api/blob/master/app_history.md, and I'd love thoughts from you all. In particular, re-reading this thread I see some great feedback on what information would be useful to include in such events, which I'm not sure we've currently captured. In general, I'd appreciate web developers supplying use cases and small code examples I could incorporate into the explainer. Specifically, the app history API proposal's Let me know what you think. In particular, if you're interested in exploring this further, please lend your support as a comment (not just thumbs-up!) in WICG/proposals#20 so that the WICG chairs can grant us a repository for incubation. |
See this exact same proposal but in a different place: WICG/proposals#6
Proposal
Add an event called
statechange
orhistorychange
that will fire on any change to the history stack, whether that be through the browser's back button, orwindow.history.pushState
or other methods.This proposed event would be similar to
popstate
, except that it would fire on all route changes regardless of the source, much likehashchange
fires on all hash changes regardless of the source.Current Problems
hashchange
events allowed javascript router libraries (e.g. React Router, vue-router) to easily respond to any routing event when the application is using hash routing.However, with the HTML5 History API, there is no equivalent event that javascript routers can listen to.
This means that routers have the following limitations/problems:
window.history.pushState
directly and must only use the Router's custom methodsReferences:
remix-run/react-router#6304
Example
Side notes
I hope I did this in the correct repo. Let me know if I need to change/update anything. Thanks.
This was created in collaboration with @joeldenning
The text was updated successfully, but these errors were encountered: