Skip to content

Commit

Permalink
fix: fix scroll when going back to initial route (#1586)
Browse files Browse the repository at this point in the history
* fix scroll when going back to initial route

* Update scroll.js
  • Loading branch information
hworld authored and yyx990803 committed Oct 11, 2017
1 parent b9bbde6 commit c166822
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/util/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { getStateKey, setStateKey } from './push-state'
const positionStore = Object.create(null)

export function setupScroll () {
// Fix for #1585 for Firefox
window.history.replaceState({ key: getStateKey() }, '')
window.addEventListener('popstate', e => {
saveScrollPosition()
if (e.state && e.state.key) {
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/specs/scroll-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ module.exports = {
return window.pageYOffset === 100
}, null, 'restore scroll position on back')

// with manual scroll restoration
// https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration
.execute(function () {
window.scrollTo(0, 100)
history.scrollRestoration = 'manual'
})
.click('li:nth-child(2) a')
.assert.containsText('.view', 'foo')
.execute(function () {
window.scrollTo(0, 200)
window.history.back()
})
.assert.containsText('.view', 'home')
.assert.evaluate(function () {
return window.pageYOffset === 100
}, null, 'restore scroll position on back with manual restoration')
.execute(function () {
history.scrollRestoration = 'auto'
})

// scroll on a popped entry
.execute(function () {
window.scrollTo(0, 50)
Expand Down

0 comments on commit c166822

Please sign in to comment.