mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
change req.params to an object instead of an array
This commit is contained in:
parent
863160ae49
commit
c6c71abf4d
|
|
@ -49,8 +49,9 @@ function Route(method, path, callbacks, options) {
|
|||
|
||||
Route.prototype.match = function(path){
|
||||
var keys = this.keys
|
||||
, params = this.params = []
|
||||
, m = this.regexp.exec(path);
|
||||
, params = this.params = {}
|
||||
, m = this.regexp.exec(path)
|
||||
, n = 0;
|
||||
|
||||
if (!m) return false;
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ Route.prototype.match = function(path){
|
|||
if (key) {
|
||||
params[key.name] = val;
|
||||
} else {
|
||||
params.push(val);
|
||||
params[n++] = val;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,8 +126,8 @@ describe('app.router', function(){
|
|||
var app = express();
|
||||
|
||||
app.get(/^\/user\/([0-9]+)\/(view|edit)?$/, function(req, res){
|
||||
var id = req.params.shift()
|
||||
, op = req.params.shift();
|
||||
var id = req.params[0]
|
||||
, op = req.params[1];
|
||||
res.end(op + 'ing user ' + id);
|
||||
});
|
||||
|
||||
|
|
@ -302,8 +302,8 @@ describe('app.router', function(){
|
|||
var app = express();
|
||||
|
||||
app.get('/api/*.*', function(req, res){
|
||||
var resource = req.params.shift()
|
||||
, format = req.params.shift();
|
||||
var resource = req.params[0]
|
||||
, format = req.params[1];
|
||||
res.end(resource + ' as ' + format);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user