Skip to content

Commit 57d8042

Browse files
ryanklarhoelterRyan Klarhölter
and
Ryan Klarhölter
authored
fix(scrollBehavior): trigger scroll behavior if same route with hash (#3592)
Co-authored-by: Ryan Klarhölter <[email protected]>
1 parent e8f3de2 commit 57d8042

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Diff for: src/history/base.js

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
isNavigationFailure,
2121
NavigationFailureType
2222
} from '../util/errors'
23+
import { handleScroll } from '../util/scroll'
2324

2425
export class History {
2526
router: Router
@@ -163,6 +164,9 @@ export class History {
163164
route.matched[lastRouteIndex] === current.matched[lastCurrentIndex]
164165
) {
165166
this.ensureURL()
167+
if (route.hash) {
168+
handleScroll(this.router, current, route, false)
169+
}
166170
return abort(createNavigationDuplicatedError(current, route))
167171
}
168172

Diff for: test/e2e/specs/scroll-behavior.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,19 @@ module.exports = {
9494
'scroll to top on new entry'
9595
)
9696

97-
.click('li:nth-child(4) a')
98-
.assert.evaluate(
99-
function () {
100-
return document.getElementById('anchor').getBoundingClientRect().top < 1
101-
},
102-
null,
103-
'scroll to anchor'
104-
)
97+
.perform(() => {
98+
for (let i = 0; i < 2; i++) {
99+
browser
100+
.click('li:nth-child(4) a')
101+
.assert.evaluate(
102+
function () {
103+
return document.getElementById('anchor').getBoundingClientRect().top < 1
104+
},
105+
null,
106+
(i === 0) ? 'scroll to anchor' : 'scroll to same anchor again'
107+
)
108+
}
109+
})
105110

106111
.click('li:nth-child(5) a')
107112
.assert.evaluate(

0 commit comments

Comments
 (0)