The window.onpopstate event is fired automatically by the browser when a user navigates between history states that a developer has set. This event is important to handle when you push to history object and then later retrieve information whenever the user presses the back/forward button of the browser.
Here's how we'll program a simple popstate event:
window.addEventListener('popstate', e => { console.log(e.state); // state data of history (remember history.state ?)})
Now we'll discuss some methods associated with the history object.