crossroads.js icon indicating copy to clipboard operation
crossroads.js copied to clipboard

Getting params as one object not on callback arguments

Open andreujuanc opened this issue 9 years ago • 1 comments

Hello!

As title says, is there a way to get the callback parameters as one object, instead of separated function arguments?

What we have now: myRouteCallback(id, name)

What I was thinking it would help me a lot: myRouteCallback(param) { param.id .. param.name..

Cheers

andreujuanc avatar Nov 20 '16 15:11 andreujuanc

Just did it myself, subscribing to routed.add and:

   var processRequest = function(params){ 
        var request = {
        };

        params.route._paramsIds.forEach(function(paramId, index) {
            request[paramId] = params.params[index];
        }, this);

        return request;
    };

But there is a problem, im using _paramsIds , and it's suposed to be private. is this the only way to do it?

andreujuanc avatar Nov 20 '16 23:11 andreujuanc