From 0b1477485a03b8adb368f9393857fe1101b0ad18 Mon Sep 17 00:00:00 2001 From: JounQin <admin@1stg.me> Date: Thu, 19 Oct 2017 20:05:00 +0800 Subject: [PATCH 1/3] fix #1834 --- src/util/scroll.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/util/scroll.js b/src/util/scroll.js index 9991adaa7..5255101cf 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -2,13 +2,15 @@ import type Router from '../index' import { assert } from './warn' -import { getStateKey, setStateKey } from './push-state' +import { getStateKey, setStateKey, supportsPushState } from './push-state' const positionStore = Object.create(null) export function setupScroll () { // Fix for #1585 for Firefox - window.history.replaceState({ key: getStateKey() }, '') + if (supportsPushState) { + window.history.replaceState({ key: getStateKey() }, '') + } window.addEventListener('popstate', e => { saveScrollPosition() if (e.state && e.state.key) { From 142d8efe5527105da74615a2e9920ab5cc97fa39 Mon Sep 17 00:00:00 2001 From: JounQin <admin@1stg.me> Date: Thu, 19 Oct 2017 20:39:30 +0800 Subject: [PATCH 2/3] judge supportsPushState before setupScroll --- src/history/html5.js | 5 +++-- src/util/scroll.js | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/history/html5.js b/src/history/html5.js index 17e1c5cbe..08bdc152d 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -5,15 +5,16 @@ import { History } from './base' import { cleanPath } from '../util/path' import { START } from '../util/route' import { setupScroll, handleScroll } from '../util/scroll' -import { pushState, replaceState } from '../util/push-state' +import { pushState, replaceState, supportsPushState } from '../util/push-state' export class HTML5History extends History { constructor (router: Router, base: ?string) { super(router, base) const expectScroll = router.options.scrollBehavior + const supportsScroll = supportsPushState && expectScroll - if (expectScroll) { + if (supportsScroll) { setupScroll() } diff --git a/src/util/scroll.js b/src/util/scroll.js index 5255101cf..9991adaa7 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -2,15 +2,13 @@ import type Router from '../index' import { assert } from './warn' -import { getStateKey, setStateKey, supportsPushState } from './push-state' +import { getStateKey, setStateKey } from './push-state' const positionStore = Object.create(null) export function setupScroll () { // Fix for #1585 for Firefox - if (supportsPushState) { - window.history.replaceState({ key: getStateKey() }, '') - } + window.history.replaceState({ key: getStateKey() }, '') window.addEventListener('popstate', e => { saveScrollPosition() if (e.state && e.state.key) { From ef3a22470cefbe96f51f7e954e0a939a50747722 Mon Sep 17 00:00:00 2001 From: JounQin <admin@1stg.me> Date: Tue, 24 Oct 2017 07:43:54 +0800 Subject: [PATCH 3/3] expectScroll -> supportsScroll --- src/history/html5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/history/html5.js b/src/history/html5.js index 08bdc152d..95c47344c 100644 --- a/src/history/html5.js +++ b/src/history/html5.js @@ -30,7 +30,7 @@ export class HTML5History extends History { } this.transitionTo(location, route => { - if (expectScroll) { + if (supportsScroll) { handleScroll(router, route, current, true) } })