Loading...
document.addEventListener('click', (e) => {
const a = e.target.closest('a');
if (!a) return;
e.preventDefault();
history.pushState({}, '', a.href);
render(a.href);
});navigation.addEventListener('navigate', (event) => {
if (!event.canIntercept || event.hashChange || event.downloadRequest) return;
const url = new URL(event.destination.url);
event.intercept({ handler: () => render(url.pathname) });
});One navigate handler covers links, forms and back or forward, so routing needs no click listeners or pushState().
intercept() for a cross-origin navigation, which throws.navigate handler checks event.canIntercept before calling event.intercept().downloadRequest and hashChange.event.intercept() instead of click handlers on links plus history.pushState().Use the Navigation API where it is supported, since one navigate event covers every navigation. Keep the History API as a fallback.
Not if a navigate handler intercepts it. Without interception, it performs a normal navigation.
Call navigation.entries(). It returns the same-origin entries of the current tab.