-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 api example #236
Conversation
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.
This was really good.
- I propose to add a few comments, explaining the part that are related to the History API
- I've updated
document.title
indisplayContent()
so that the history in the navigator looks better.
}); | ||
|
||
// Handle forward/back buttons | ||
window.addEventListener("popstate", (event) => { |
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.
Yes! This is one case where window
is needed! It is the object window
(and not the global scope) we are using.
Nice!
Co-authored-by: Jean-Yves Perrier <[email protected]>
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.
👍 Nice!
@teoli2003 , the point of this is to replace https://developer.mozilla.org/en-US/docs/Web/API/History_API/Example, which I don't think is viable as an example.
I've used https://github.com/lesjames/history-api-demo, which in turn is based on http://html5doctor.com/history-api/, as a starting point, but have pretty much completely rewritten it.
The general idea is to show how to use the history API to allow back/forward navigation to work when you're doing a single-page app thing using fetch().
However I don't really know what I'm doing here so I'm very open to feedback!