Skip to content

Commit 4d18aec

Browse files
committed
Normalize onclick rebuild path.
1 parent b2fd128 commit 4d18aec

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

page.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
}
167167
if (true === options.hashbang) hashbang = true;
168168
if (!dispatch) return;
169-
page.replace(page.getCurrentUrl(), null, true, dispatch);
169+
page.replace(page.getPath(), null, true, dispatch);
170170
};
171171

172172
/**
@@ -355,17 +355,22 @@
355355
};
356356

357357
/**
358-
* Get the URL for cases that path is not provided.
358+
* Get the path for cases that it is not provided.
359359
*
360360
* Like:
361361
*
362362
* - page.start with dispatch is set to true.
363363
* - On popstate event when state is not provided.
364+
* - Rebuild path on click event listener.
364365
*
365-
* @return {str} URL current URL location
366-
*/
367-
page.getCurrentUrl = function(){
368-
return (hashbang && ~location.hash.indexOf('#!')) ? location.hash.substr(2) + location.search : location.pathname + location.search + location.hash;
366+
* @param {object} location to generate path.
367+
* @return {str} path path generated.
368+
*/
369+
page.getPath = function(oLocation){
370+
oLocation = oLocation || location;
371+
return (hashbang && ~oLocation.hash.indexOf('#!')) ?
372+
oLocation.hash.substr(2) + oLocation.search :
373+
oLocation.pathname + oLocation.search + oLocation.hash;
369374
};
370375

371376
/**
@@ -543,7 +548,7 @@
543548
var path = e.state.path;
544549
page.replace(path, e.state);
545550
} else {
546-
page.show(page.getCurrentUrl(), null, true, dispatch);
551+
page.show(page.getPath(), null, true, dispatch);
547552
}
548553
};
549554
})();
@@ -590,7 +595,7 @@
590595

591596

592597
// rebuild path
593-
var path = el.pathname + el.search + (el.hash || '');
598+
var path = page.getPath(el);
594599

595600
// strip leading "/[drive letter]:" on NW.js on Windows
596601
if (typeof process !== 'undefined' && path.match(/^\/[a-zA-Z]:\//)) {

0 commit comments

Comments
 (0)