From 10ddaeb7a3a2337f5a355f10b49c13b0423ee342 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Dec 2017 08:16:09 -0500 Subject: [PATCH] dont navigate on hashchange --- runtime/app.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/runtime/app.js b/runtime/app.js index c46681d..25e342b 100644 --- a/runtime/app.js +++ b/runtime/app.js @@ -8,8 +8,6 @@ const scroll_history = {}; let uid = 1; let cid; -window.scroll_history = scroll_history; - if ('scrollRestoration' in history) { history.scrollRestoration = 'manual' } @@ -108,6 +106,8 @@ const app = { const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString'; const href = svg ? a.href.baseVal : a.href; + if (href === window.location.href) return; + // Ignore if tag has // 1. 'download' attribute // 2. rel='external' attribute @@ -116,9 +116,16 @@ const app = { // Ignore if has a target if (svg ? a.target.baseVal : a.target) return; + const url = new URL(href); + + // Don't handle hash changes + if (url.pathname === window.location.pathname && url.search === window.location.search) { + return; + } + const scroll = scroll_state(); - if (navigate(new URL(a.href), null)) { + if (navigate(url, null)) { event.preventDefault(); } });