@@ -19,11 +19,20 @@ export class HTML5History extends History {
19
19
constructor ( router : VueRouter , base : ?string ) {
20
20
super ( router , base )
21
21
22
+ const initialLocation = getLocation ( this . base )
23
+ this . transitionTo ( initialLocation , route => {
24
+ // possible redirect on start
25
+ const url = cleanPath ( this . base + this . current . fullPath )
26
+ if ( initialLocation !== url ) {
27
+ replaceState ( url )
28
+ }
29
+ } )
30
+
22
31
const expectScroll = router . options . scrollBehavior
23
32
window . addEventListener ( 'popstate' , e => {
24
33
_key = e . state && e . state . key
25
34
const current = this . current
26
- this . transitionTo ( this . getLocation ( ) , next => {
35
+ this . transitionTo ( getLocation ( this . base ) , next => {
27
36
if ( expectScroll ) {
28
37
this . handleScroll ( next , current , true )
29
38
}
@@ -37,14 +46,6 @@ export class HTML5History extends History {
37
46
}
38
47
}
39
48
40
- onInit ( ) {
41
- // possible redirect on start
42
- const url = cleanPath ( this . base + this . current . fullPath )
43
- if ( this . getLocation ( ) !== url ) {
44
- replaceState ( url )
45
- }
46
- }
47
-
48
49
go ( n : number ) {
49
50
window . history . go ( n )
50
51
}
@@ -65,10 +66,6 @@ export class HTML5History extends History {
65
66
} )
66
67
}
67
68
68
- getLocation ( ) : string {
69
- return getLocation ( this . base )
70
- }
71
-
72
69
handleScroll ( to : Route , from : Route , isPop : boolean ) {
73
70
const router = this . router
74
71
if ( ! router . app ) {
0 commit comments