millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

Getting params as one object not on callback arguments #154

Open andreujuanc opened 7 years ago

andreujuanc commented 7 years ago

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 commented 7 years ago

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?