freecoding.school100% FREE · NO SIGNUP
Await StationISSUE #22 of 26

history api · pushState · replaceState

PromissaVSRace Condition Rex
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

Race Condition Rex attacks — common mistakes

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>
▶ Open the interactive comic issue
‹ Cookies · Document.CookieLocation · Hash · Search · Hostname ›