Intercept link clicks for client-side routing

This commit is contained in:
Chris Wanstrath 2026-02-26 18:49:48 -08:00
parent 98a1c1ad97
commit 68274d8651

View File

@ -14,6 +14,7 @@ export function initRouter(render: () => void) {
document.addEventListener('click', e => {
const a = (e.target as Element).closest('a')
if (!a || !a.href || a.origin !== location.origin || a.target === '_blank') return
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
e.preventDefault()
history.pushState(null, '', a.href)
route()