SPA back button: what event fires and how do you handle it?

Tests History API literacy. Strong answer: popstate event, PopStateEvent type, restore UI via event.state, and zero-delay setTimeout for DOM sync. Red flag: confusing popstate with pushState or using hashchange for modern History API routing.
Tests mastery of the History API and the navigation-to-DOM timing gap in SPAs. Strong answers name the popstate event on window, type the listener as PopStateEvent, read event.state to rebuild the prior UI, guard against null state, and cite the zero-delay setTimeout pattern when document readiness lags behind window.location after the URL changes. Red flag: thinking history.pushState fires an event, or defaulting to hashchange instead of popstate for modern History API routing.
Read the original → developer.mozilla.org
- #typescript
- #history api
- #spa
- #popstate
- #browser events
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.