@@ -56,16 +56,15 @@ class History {
56
56
if ( typeof this . readState === 'function' )
57
57
state = this . readState ( entry . key ) ;
58
58
59
- this . location = this . _createLocation ( path , state , entry ) ;
59
+ this . _handleChange ( path , state , entry , NavigationTypes . POP , false ) ;
60
60
}
61
61
62
62
handlePop ( path , entry = { } ) {
63
63
var state = null ;
64
64
if ( entry . key && typeof this . readState === 'function' )
65
65
state = this . readState ( entry . key ) ;
66
66
67
- this . location = this . _createLocation ( path , state , entry , NavigationTypes . POP ) ;
68
- this . _notifyChange ( ) ;
67
+ this . _handleChange ( path , state , entry , NavigationTypes . POP ) ;
69
68
}
70
69
71
70
createRandomKey ( ) {
@@ -92,7 +91,7 @@ class History {
92
91
var key = this . _saveNewState ( state ) ;
93
92
94
93
var entry = null ;
95
- if ( this . location && this . location . path === path ) {
94
+ if ( this . path === path ) {
96
95
entry = this . replace ( path , key ) || { } ;
97
96
} else {
98
97
entry = this . push ( path , key ) || { } ;
@@ -104,8 +103,7 @@ class History {
104
103
this . constructor . name
105
104
) ;
106
105
107
- this . location = this . _createLocation ( path , state , entry , NavigationTypes . PUSH ) ;
108
- this . _notifyChange ( ) ;
106
+ this . _handleChange ( path , state , entry , NavigationTypes . PUSH ) ;
109
107
}
110
108
111
109
replaceState ( state , path ) {
@@ -119,8 +117,7 @@ class History {
119
117
this . constructor . name
120
118
) ;
121
119
122
- this . location = this . _createLocation ( path , state , entry , NavigationTypes . REPLACE ) ;
123
- this . _notifyChange ( ) ;
120
+ this . _handleChange ( path , state , entry , NavigationTypes . REPLACE ) ;
124
121
}
125
122
126
123
back ( ) {
@@ -131,11 +128,19 @@ class History {
131
128
this . go ( 1 ) ;
132
129
}
133
130
131
+ _handleChange ( path , state , entry , navigationType , notify = true ) {
132
+ this . path = path ;
133
+ this . location = this . _createLocation ( path , state , entry , navigationType ) ;
134
+
135
+ if ( notify )
136
+ this . _notifyChange ( ) ;
137
+ }
138
+
134
139
_createLocation ( path , state , entry , navigationType ) {
135
140
var pathname = getPathname ( path ) ;
136
141
var queryString = getQueryString ( path ) ;
137
142
var query = queryString ? this . parseQueryString ( queryString ) : null ;
138
- return new Location ( path , pathname , query , { ...state , ...entry } , navigationType ) ;
143
+ return new Location ( pathname , query , { ...state , ...entry } , navigationType ) ;
139
144
}
140
145
141
146
}
0 commit comments