File tree Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Expand file tree Collapse file tree 3 files changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export class History {
17
17
go: ( n : number ) => void ;
18
18
push: ( loc : RawLocation ) => void ;
19
19
replace: ( loc : RawLocation ) => void ;
20
+ ensureURL: ( ) => void ;
20
21
21
22
constructor ( router : VueRouter , base : ?string ) {
22
23
this . router = router
@@ -37,11 +38,13 @@ export class History {
37
38
this . confirmTransition ( route , ( ) => {
38
39
this . updateRoute ( route )
39
40
cb && cb ( route )
41
+ this . ensureURL ( )
40
42
} )
41
43
}
42
44
43
45
confirmTransition ( route : Route , cb : Function ) {
44
46
if ( isSameRoute ( route , this . current ) ) {
47
+ this . ensureURL ( )
45
48
return
46
49
}
47
50
Original file line number Diff line number Diff line change @@ -15,12 +15,7 @@ export class HashHistory extends History {
15
15
}
16
16
17
17
ensureSlash ( )
18
- this . transitionTo ( getHash ( ) , route => {
19
- // possible redirect on start
20
- if ( getHash ( ) !== route . fullPath ) {
21
- replaceHash ( route . fullPath )
22
- }
23
- } )
18
+ this . transitionTo ( getHash ( ) )
24
19
25
20
window . addEventListener ( 'hashchange' , ( ) => {
26
21
this . onHashChange ( )
@@ -37,6 +32,12 @@ export class HashHistory extends History {
37
32
}
38
33
}
39
34
35
+ ensureURL ( ) {
36
+ if ( getHash ( ) !== this . current . fullPath ) {
37
+ replaceHash ( this . current . fullPath )
38
+ }
39
+ }
40
+
40
41
onHashChange ( ) {
41
42
if ( ! ensureSlash ( ) ) {
42
43
return
Original file line number Diff line number Diff line change @@ -19,14 +19,7 @@ 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
- } )
22
+ this . transitionTo ( getLocation ( this . base ) )
30
23
31
24
const expectScroll = router . options . scrollBehavior
32
25
window . addEventListener ( 'popstate' , e => {
@@ -66,6 +59,12 @@ export class HTML5History extends History {
66
59
} )
67
60
}
68
61
62
+ ensureURL ( ) {
63
+ if ( getLocation ( this . base ) !== this . current . fullPath ) {
64
+ replaceState ( cleanPath ( this . base + this . current . fullPath ) )
65
+ }
66
+ }
67
+
69
68
handleScroll ( to : Route , from : Route , isPop : boolean ) {
70
69
const router = this . router
71
70
if ( ! router . app ) {
You can’t perform that action at this time.
0 commit comments