diff --git a/templates/src/client/start/index.ts b/templates/src/client/start/index.ts index 17979a3b4..d2dfa0ada 100644 --- a/templates/src/client/start/index.ts +++ b/templates/src/client/start/index.ts @@ -83,6 +83,10 @@ function handle_click(event: MouseEvent) { const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString'; const href = String(svg ? (a).href.baseVal : a.href); + if (location.hash && href === location.href) { + return; + } + if (href === location.href) { event.preventDefault(); return; diff --git a/test/apps/scroll/src/routes/tall-page.html b/test/apps/scroll/src/routes/tall-page.html index 7e42ff94e..3a92a984b 100644 --- a/test/apps/scroll/src/routes/tall-page.html +++ b/test/apps/scroll/src/routes/tall-page.html @@ -1,3 +1,4 @@ +scroll to foo
diff --git a/test/apps/scroll/test.ts b/test/apps/scroll/test.ts index 0c0db39b0..8b7efb9d6 100644 --- a/test/apps/scroll/test.ts +++ b/test/apps/scroll/test.ts @@ -33,6 +33,24 @@ describe('scroll', function() { assert.ok(scrollY > 0, scrollY); }); + it('scrolls to any deeplink if it was already active', async () => { + await page.goto(`${base}/tall-page#foo`); + await start(); + + let scrollY = await page.evaluate(() => window.scrollY); + assert.ok(scrollY > 0, scrollY); + + scrollY = await page.evaluate(() => { + window.scrollTo(0, 0) + return window.scrollY + }); + assert.ok(scrollY === 0, scrollY); + + await page.click('[href="tall-page#foo"]'); + scrollY = await page.evaluate(() => window.scrollY); + assert.ok(scrollY > 0, scrollY); + }); + it('resets scroll when a link is clicked', async () => { await page.goto(`${base}/tall-page#foo`); await start();