Skip to content

Commit

Permalink
Handle the prefixed paths in the path method
Browse files Browse the repository at this point in the history
  • Loading branch information
mquandalle committed Oct 3, 2015
1 parent bbba4e3 commit e030416
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@ Router.prototype.path = function(pathDef, fields, queryParams) {
pathDef = this._routesMap[pathDef].pathDef;
}

var path = "";

// Prefix the path with the router global prefix
if (this._basePath) {
path += this._basePath + "/";
}

fields = fields || {};
var regExp = /(:[\w\(\)\\\+\*\.\?]+)+/g;
var path = pathDef.replace(regExp, function(key) {
path += pathDef.replace(regExp, function(key) {
var firstRegexpChar = key.indexOf("(");
// get the content behind : and (\\d+/)
key = key.substring(1, (firstRegexpChar > 0)? firstRegexpChar: undefined);
Expand All @@ -153,7 +160,8 @@ Router.prototype.path = function(pathDef, fields, queryParams) {
return encodeURIComponent(encodeURIComponent(fields[key] || ""));
});

path = path.replace(/\/\/+/g, "/"); // Replace multiple slashes with single slash
// Replace multiple slashes with single slash
path = path.replace(/\/\/+/g, "/");

// remove trailing slash
// but keep the root slash if it's the only one
Expand Down

0 comments on commit e030416

Please sign in to comment.