File tree 3 files changed +23
-11
lines changed
3 files changed +23
-11
lines changed Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
3
import { inBrowser } from './dom'
4
- import { saveScrollPosition } from './scroll'
4
+ import { saveScrollPosition , clearPositionStore } from './scroll'
5
5
import { genStateKey , setStateKey , getStateKey } from './state-key'
6
6
import { extend } from './misc'
7
7
@@ -28,6 +28,7 @@ export function pushState (url?: string, replace?: boolean) {
28
28
// DOM Exception 18 where it limits to 100 pushState calls
29
29
const history = window . history
30
30
try {
31
+ clearPositionStore ( )
31
32
if ( replace ) {
32
33
// preserve existing history state as it could be overriden by the user
33
34
const stateCopy = extend ( { } , history . state )
Original file line number Diff line number Diff line change 2
2
3
3
import type Router from '../index'
4
4
import { assert } from './warn'
5
- import { getStateKey , setStateKey } from './state-key'
5
+ import { getStateKey , setStateKey , getCurrentStateKey } from './state-key'
6
6
import { extend } from './misc'
7
7
8
8
const positionStore = Object . create ( null )
@@ -173,3 +173,12 @@ function scrollToPosition (shouldScroll, position) {
173
173
}
174
174
}
175
175
}
176
+
177
+ export function clearPositionStore ( ) {
178
+ const key = getCurrentStateKey ( )
179
+ for ( var i in positionStore ) {
180
+ if ( Number ( i ) > key ) {
181
+ delete ( positionStore [ i ] )
182
+ }
183
+ }
184
+ }
Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
import { inBrowser } from './dom'
3
3
4
- // use User Timing api (if present) for more accurate key precision
5
- const Time =
6
- inBrowser && window . performance && window . performance . now
7
- ? window . performance
8
- : Date
4
+ export function getCurrentStateKey ( ) : number {
5
+ const state = window . history . state
6
+ if ( state && typeof state . key === 'number' ) {
7
+ return state . key
8
+ }
9
+ return 1
10
+ }
9
11
10
- export function genStateKey ( ) : string {
11
- return Time . now ( ) . toFixed ( 3 )
12
+ export function genStateKey ( ) : number {
13
+ return getCurrentStateKey ( ) + 1
12
14
}
13
15
14
- let _key : string = genStateKey ( )
16
+ let _key : number = inBrowser ? getCurrentStateKey ( ) : - 1
15
17
16
18
export function getStateKey ( ) {
17
19
return _key
18
20
}
19
21
20
- export function setStateKey ( key : string ) {
22
+ export function setStateKey ( key : number ) {
21
23
return ( _key = key )
22
24
}
You can’t perform that action at this time.
0 commit comments