Intercept link clicks for client-side routing
This commit is contained in:
parent
98a1c1ad97
commit
68274d8651
|
|
@ -14,6 +14,7 @@ export function initRouter(render: () => void) {
|
||||||
document.addEventListener('click', e => {
|
document.addEventListener('click', e => {
|
||||||
const a = (e.target as Element).closest('a')
|
const a = (e.target as Element).closest('a')
|
||||||
if (!a || !a.href || a.origin !== location.origin || a.target === '_blank') return
|
if (!a || !a.href || a.origin !== location.origin || a.target === '_blank') return
|
||||||
|
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
history.pushState(null, '', a.href)
|
history.pushState(null, '', a.href)
|
||||||
route()
|
route()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user