Skip to content

Commit c166822

Browse files
hworldyyx990803
authored andcommitted
fix: fix scroll when going back to initial route (#1586)
* fix scroll when going back to initial route * Update scroll.js
1 parent b9bbde6 commit c166822

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/util/scroll.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { getStateKey, setStateKey } from './push-state'
77
const positionStore = Object.create(null)
88

99
export function setupScroll () {
10+
// Fix for #1585 for Firefox
11+
window.history.replaceState({ key: getStateKey() }, '')
1012
window.addEventListener('popstate', e => {
1113
saveScrollPosition()
1214
if (e.state && e.state.key) {

test/e2e/specs/scroll-behavior.js

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ module.exports = {
2020
return window.pageYOffset === 100
2121
}, null, 'restore scroll position on back')
2222

23+
// with manual scroll restoration
24+
// https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration
25+
.execute(function () {
26+
window.scrollTo(0, 100)
27+
history.scrollRestoration = 'manual'
28+
})
29+
.click('li:nth-child(2) a')
30+
.assert.containsText('.view', 'foo')
31+
.execute(function () {
32+
window.scrollTo(0, 200)
33+
window.history.back()
34+
})
35+
.assert.containsText('.view', 'home')
36+
.assert.evaluate(function () {
37+
return window.pageYOffset === 100
38+
}, null, 'restore scroll position on back with manual restoration')
39+
.execute(function () {
40+
history.scrollRestoration = 'auto'
41+
})
42+
2343
// scroll on a popped entry
2444
.execute(function () {
2545
window.scrollTo(0, 50)

0 commit comments

Comments
 (0)