Skip to content

Commit

Permalink
fix(scrollBehavior): trigger scroll behavior if same route with hash (v…
Browse files Browse the repository at this point in the history
…uejs#3592)

Co-authored-by: Ryan Klarhölter <[email protected]>
  • Loading branch information
ryanklarhoelter and Ryan Klarhölter authored Oct 8, 2021
1 parent e8f3de2 commit 57d8042
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/history/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isNavigationFailure,
NavigationFailureType
} from '../util/errors'
import { handleScroll } from '../util/scroll'

export class History {
router: Router
Expand Down Expand Up @@ -163,6 +164,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))
}

Expand Down
21 changes: 13 additions & 8 deletions test/e2e/specs/scroll-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 57d8042

Please sign in to comment.