diff --git a/src/history/base.js b/src/history/base.js index 5f2bad870..0ec939dff 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,9 @@ export class History { route.matched[lastRouteIndex] === current.matched[lastCurrentIndex] ) { this.ensureURL() + if (route.hash) { + handleScroll(this.router, current, route, false) + } return abort(createNavigationDuplicatedError(current, route)) } 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(