Promissa saysThe History API changes the URL without a page reload — the engine behind single-page apps.
history.pushState(state, "", "/new-path") adds a history entry and updates the URL with no reload; replaceState swaps the current entry. The browser fires popstate on back/forward so you can restore the matching view. This is how SPA routers navigate — change the URL, render the right component, no full reload.
Power-ups you unlock
pushState adds an entry; replaceState swaps
URL changes with no reload
popstate fires on back/forward
The basis of SPA client-side routing
Race Condition Rex attacks — common mistakes
Forgetting to handle popstate (back button breaks)
pushState to a URL the server can’t serve on refresh
Storing huge objects in the state
Boss battlepushState a new path, then handle popstate to react to back navigation.
Example code
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>history.pushState({page:2},'','?page=2');
addEventListener('popstate',e=>document.getElementById('o').textContent='popped: '+JSON.stringify(e.state));
document.getElementById('o').textContent='url is now '+location.search;</script></body></html>