@@ -6,6 +6,8 @@ const Url = module.exports = {
6
6
7
7
_onPopStateCbs : [ ]
8
8
, _isHash : false
9
+ , current_location : ""
10
+ , previous_location : ""
9
11
10
12
/**
11
13
* queryString
@@ -172,10 +174,11 @@ const Url = module.exports = {
172
174
*
173
175
* @name getLocation
174
176
* @function
177
+ * @param {Boolean } excludeHash If `true`, the location hash will not be appended in the result.
175
178
* @return {String } The page url (without domain).
176
179
*/
177
- , getLocation ( ) {
178
- return window . location . pathname + window . location . search + window . location . hash ;
180
+ , getLocation ( excludeHash ) {
181
+ return window . location . pathname + window . location . search + ( excludeHash ? "" : window . location . hash ) ;
179
182
}
180
183
181
184
/**
@@ -198,7 +201,12 @@ const Url = module.exports = {
198
201
} , 0 ) ;
199
202
Url . _isHash = true ;
200
203
}
201
- return location . hash = newHash ;
204
+
205
+
206
+ location . hash = newHash ;
207
+ Url . previous_location = Url . current_location
208
+ Url . current_location = Url . getLocation ( true )
209
+ return newHash
202
210
}
203
211
204
212
/**
@@ -215,6 +223,10 @@ const Url = module.exports = {
215
223
* @return {String } The set url.
216
224
*/
217
225
, _updateAll ( s , push , triggerPopState ) {
226
+ if ( push ) {
227
+ Url . previous_location = Url . current_location
228
+ }
229
+ Url . current_location = Url . getLocation ( true )
218
230
window . history [ push ? "pushState" : "replaceState" ] ( null , "" , s ) ;
219
231
if ( triggerPopState ) {
220
232
Url . triggerPopStateCb ( { } ) ;
@@ -250,6 +262,19 @@ const Url = module.exports = {
250
262
* @function
251
263
*/
252
264
, triggerPopStateCb ( e ) {
265
+
266
+ setTimeout ( function ( ) {
267
+ Url . current_location = Url . getLocation ( true )
268
+ } , 0 )
269
+
270
+ if ( Url . previous_location === Url . current_location ) {
271
+ Url . _isHash = true
272
+ setTimeout ( function ( ) {
273
+ Url . _isHash = false
274
+ window . history . back ( )
275
+ } , 0 ) ;
276
+ return
277
+ }
253
278
if ( this . _isHash ) { return ; }
254
279
this . _onPopStateCbs . forEach ( function ( c ) {
255
280
c ( e )
@@ -298,5 +323,7 @@ const Url = module.exports = {
298
323
this . _updateAll ( window . location . pathname + window . location . hash , push || false , trigger || false ) ;
299
324
}
300
325
301
- , version : "2.5 .0"
326
+ , version : "2.6 .0"
302
327
} ;
328
+
329
+ Url . current_location = Url . getLocation ( true )
0 commit comments