diff --git a/jsRoute.js b/jsRoute.js index c2271fc..fb07855 100644 --- a/jsRoute.js +++ b/jsRoute.js @@ -5,7 +5,7 @@ var route = { routes: [], funcs: [], - actualURL: '', + currentHash: '', interval: null, add: function(route, func){ @@ -20,14 +20,14 @@ var route = { }, _check: function() { - if( this.actualURL != document.location.href ) { - this.actualURL = document.location.href; + if( document.location.hash && this.currentHash != document.location.hash) { + this.currentHash = document.location.hash.slice(1); this._update(); } }, _findAndExecute: function(route){ - for(var i=0; i< this.routes.length; i++){ + for( var i = 0, l = this.routes.length; i < l; i++ ){ var re = new RegExp(this.routes[i]); var match = route.match(re); @@ -40,7 +40,7 @@ var route = { }, _update: function(){ - var hash = location.hash.slice(1); + var hash = this.currentHash; this._findAndExecute(hash); },