Pushing on the history - history.pushState()

This is really fun. You can change the browser URL without hitting the server with an HTTP request. If you run the following JS in your browser, your browser will change the path from whatever it is (domain.com/abc/egh) to  /i_am_awesome (domain.com/i_am_awesome) without actually navigating to any page:

history.pushState({myName: "Mehul"}, "This is title of page", "/i_am_awesome");history.pushState({page2: "Packt"}, "This is page2", "/page2_packt"); // <-- state is currently here

The History API doesn't care whether the page actually exists on the server or not. It'll just replace the URL as it is instructed.

The  popstate event when triggered with the browser's back/forward button, will fire the ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.