From 860b007b108da67d5af4d0ddc8d0606ca87b937f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryan=20Klarh=C3=B6lter?= Date: Mon, 12 Jul 2021 14:07:32 +0200 Subject: [PATCH 1/3] fix(scrollBehavior): trigger scroll behavior if same route close #1668, #974 --- src/history/base.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/history/base.js b/src/history/base.js index 5f2bad870..6035cae70 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -20,6 +20,7 @@ import { isNavigationFailure, NavigationFailureType } from '../util/errors' +import { handleScroll } from '../util/scroll' export class History { router: Router @@ -161,6 +162,7 @@ export class History { route.matched[lastRouteIndex] === current.matched[lastCurrentIndex] ) { this.ensureURL() + handleScroll(this.router, current, route, false) return abort(createNavigationDuplicatedError(current, route)) } From 2ebf4081b983b408f9582a4d5bef097c821cd015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryan=20Klarh=C3=B6lter?= Date: Thu, 7 Oct 2021 15:59:59 +0200 Subject: [PATCH 2/3] fix(scrollBehavior): add e2e test for scroll behavior if same route --- test/e2e/specs/scroll-behavior.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/e2e/specs/scroll-behavior.js b/test/e2e/specs/scroll-behavior.js index db317d591..d7469e9e0 100644 --- a/test/e2e/specs/scroll-behavior.js +++ b/test/e2e/specs/scroll-behavior.js @@ -94,14 +94,19 @@ module.exports = { 'scroll to top on new entry' ) - .click('li:nth-child(4) a') - .assert.evaluate( - function () { - return document.getElementById('anchor').getBoundingClientRect().top < 1 - }, - null, - 'scroll to anchor' - ) + .perform(() => { + for (let i = 0; i < 2; i++) { + browser + .click('li:nth-child(4) a') + .assert.evaluate( + function () { + return document.getElementById('anchor').getBoundingClientRect().top < 1 + }, + null, + (i === 0) ? 'scroll to anchor' : 'scroll to same anchor again' + ) + } + }) .click('li:nth-child(5) a') .assert.evaluate( From df2c9de9cb781723dcb1ee80946d81be6343db0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryan=20Klarh=C3=B6lter?= Date: Fri, 8 Oct 2021 11:45:42 +0200 Subject: [PATCH 3/3] fix(scrollBehavior): trigger scroll behavior on same route for anchor links only --- src/history/base.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/history/base.js b/src/history/base.js index 6035cae70..0ec939dff 100644 --- a/src/history/base.js +++ b/src/history/base.js @@ -162,7 +162,9 @@ export class History { route.matched[lastRouteIndex] === current.matched[lastCurrentIndex] ) { this.ensureURL() - handleScroll(this.router, current, route, false) + if (route.hash) { + handleScroll(this.router, current, route, false) + } return abort(createNavigationDuplicatedError(current, route)) }