A History API router has no single place where navigations start. It catches link clicks itself, misses form submissions and location.href = … unless it patches them, and learns about back and forward only from popstate, after the URL has changed and too late to cancel. pushState() is synchronous, so there's no notion of a navigation still loading, and the history list can't be read.
The Navigation API (window.navigation) fixes this with one event and a few objects:
navigatefires before every navigation of the frame: link clicks, form submissions (withevent.formData),locationchanges,pushState()/replaceState(), back/forward, reloads andnavigation.navigate(). It reportsnavigationType(push,replace,reload,traverse),destination,userInitiated,hashChange,downloadRequestand asignal.preventDefault()cancels it whencancelableis true.event.intercept({ handler })turns it into a same-document navigation. The URL andnavigation.currentEntrychange at once; the handler's promise is the navigation. The browser shows loading while it runs, firesnavigatesuccessornavigateerror, then resets focus and scroll. It's allowed only whencanInterceptis true: a same-origin URL, and not a traversal to another document.- Methods return promises.
navigate(),back(),forward(),traverseTo(key)andreload()return{ committed, finished }. - Entries.
navigation.entries()lists this origin's contiguous entries, each withurl,key,indexandgetState();currententrychangefires on every change. This state is separate fromhistory.state.
Two things stay out of reach: navigations to other origins and back/forward to other documents can be watched but not intercepted, and those traversals can't be cancelled. Every engine has it now: Chrome 102, Firefox 147, Safari 26.2.