Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
feat($router): ensure trailing slash in location
Browse files Browse the repository at this point in the history
  • Loading branch information
crissdev committed Oct 16, 2014
1 parent 4e50a07 commit 3a38122
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/app/shared/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@ define(function(require, exports, module) {
serviceInstance = {};


function ensureTrailingSlash(location) {
var index = location.indexOf('?');
if (index > 0 && location[index - 1] !== '/') {
location = location.slice(0, index) + '/' + location.slice(index);
}
else if (index < 0 && location[location.length - 1] !== '/') {
location += '/';
}
var previouslyActive = hasher.changed.active;
hasher.changed.active = false;
hasher.replaceHash(location);
hasher.changed.active = previouslyActive;

return location;
}

crossroads.greedyEnabled = !!config.greedyEnabled;
crossroads.ignoreState = config.hasOwnProperty('ignoreState') ? !!config.ignoreState : true;

hasher.prependHash = config.prependHash || '';
hasher.changed.add(function(newHash) { crossroads.parse(newHash); });
hasher.initialized.addOnce(function(newHash) { crossroads.parse(newHash); });

hasher.changed.add(function(newHash) { crossroads.parse(ensureTrailingSlash(newHash)); });
hasher.initialized.addOnce(function(newHash) { crossroads.parse(ensureTrailingSlash(newHash)); });

serviceInstance.when = function(pattern, options) {
if (pattern === null) {
Expand Down

0 comments on commit 3a38122

Please sign in to comment.