Skip to content

Commit

Permalink
fix(scroll): do not restore on push
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 1, 2020
1 parent d7dd3b7 commit 3f79195
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
25 changes: 25 additions & 0 deletions e2e/specs/scroll-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ module.exports = {
'restores scroll position when reloading'
)

// going again to a popped entry should not restore the saved position
.click('li:nth-child(1) a')
.waitForElementPresent('.view.home', TIMEOUT)
.click('li:nth-child(4) a')
.waitForElementPresent('.view.bar', TIMEOUT)
// at this point we scrolled to the anchor, scroll again somewhere else
// and then go back
.execute(function () {
window.scrollTo(0, 100)
window.history.back()
})
.waitForElementPresent('.view.home', TIMEOUT)
// go to the same location again but without using history.forward
.click('li:nth-child(4) a')
.waitForElementPresent('.view.bar', TIMEOUT)
.assert.evaluate(
function () {
return (
document.getElementById('anchor').getBoundingClientRect().top < 1
)
},
null,
'scroll to anchor'
)

.end()
},
}
8 changes: 5 additions & 3 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,11 @@ export function createRouter(options: RouterOptions): Router {
// duplicated navigation (e.g. same anchor navigation). It needs exposing
// the navigation information (type, direction)
if (isBrowser) {
const savedScroll = getSavedScrollPosition(
getScrollKey(toLocation.fullPath, 0)
)
// if we are pushing, we cannot have a saved position. This is important
// when visiting /b from /a, scrolling, going back to /a by with the back
// button and then clicking on a link to /b instead of the forward button
const savedScroll =
!isPush && getSavedScrollPosition(getScrollKey(toLocation.fullPath, 0))
handleScroll(
toLocation,
from,
Expand Down

0 comments on commit 3f79195

Please sign in to comment.