Skip to content

Commit

Permalink
Added a property 'hashbangEnabled' to enable the use of hashtag. Is n…
Browse files Browse the repository at this point in the history
…ot enabled by default.
  • Loading branch information
antoinegrant committed Dec 13, 2014
1 parent 56986af commit a89f65c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions modules/locations/HashLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ var Path = require('../utils/Path');
* query string.
*/
function getHashPath() {
return Path.decode(
// We can't use window.location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!
window.location.href.split('#')[1] || ''
);
// We can't use window.location.hash here because it's not
// consistent across browsers - Firefox will pre-decode it!
var hash = window.location.href.split('#')[1] || '';
if ( HashLocation.hashbangEnabled && hash.match('!') !== null ) {
hash = hash.substr(1);
}
return Path.decode(hash);
}

var _actionType;
Expand Down Expand Up @@ -60,6 +62,8 @@ function onHashChange() {
* A Location that uses `window.location.hash`.
*/
var HashLocation = {

hashbangEnabled: false,

addChangeListener: function (listener) {
_changeListeners.push(listener);
Expand All @@ -81,12 +85,12 @@ var HashLocation = {

push: function (path) {
_actionType = LocationActions.PUSH;
window.location.hash = Path.encode(path);
window.location.hash = (this.hashbangEnabled ? '!' : '') + Path.encode(path);
},

replace: function (path) {
_actionType = LocationActions.REPLACE;
window.location.replace(window.location.pathname + '#' + Path.encode(path));
window.location.replace(window.location.pathname + '#' + (this.hashbangEnabled ? '!' : '') + Path.encode(path));
},

pop: function () {
Expand Down

0 comments on commit a89f65c

Please sign in to comment.