@@ -19,11 +19,20 @@ export class HTML5History extends History {
1919 constructor ( router : VueRouter , base : ?string ) {
2020 super ( router , base )
2121
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+
2231 const expectScroll = router . options . scrollBehavior
2332 window . addEventListener ( 'popstate' , e => {
2433 _key = e . state && e . state . key
2534 const current = this . current
26- this . transitionTo ( this . getLocation ( ) , next => {
35+ this . transitionTo ( getLocation ( this . base ) , next => {
2736 if ( expectScroll ) {
2837 this . handleScroll ( next , current , true )
2938 }
@@ -37,14 +46,6 @@ export class HTML5History extends History {
3746 }
3847 }
3948
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-
4849 go ( n : number ) {
4950 window . history . go ( n )
5051 }
@@ -65,10 +66,6 @@ export class HTML5History extends History {
6566 } )
6667 }
6768
68- getLocation ( ) : string {
69- return getLocation ( this . base )
70- }
71-
7269 handleScroll ( to : Route , from : Route , isPop : boolean ) {
7370 const router = this . router
7471 if ( ! router . app ) {
0 commit comments