millermedeiros / crossroads.js

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

URL param names are lost : route handler should get param object with names as fields #144

Open visionscaper opened 8 years ago

visionscaper commented 8 years ago

Hello,

I'm interested in using crossroads.js, but unfortunately I can't use it as is, because crossroads seems to throw away the names of the URL parameters. This, IMHO is a fundamental flaw.

Example:

This is how you are suppose to use Crossroads.js:

crossroads.addRoute('/news/{id}/:date:', function(id, date) {
  console.log(id +' - '+ date);
});

I can't define my route handlers like that, because I need to forward the URL parameters (e.g. id and date) without knowing what they are. So I need something like this:

crossroads.addRoute('/news/{id}/:date:', function(params) {
  goToState(stateHandlingThisRoute, params); //params === { id : <some id>,  data : <some date> }
});

Only a state named stateHandlingThisRoute knows what to expect in params; at the level where I add the handler, I don't know!

So, if the above is not possible, Crossroads can't be used in a larger architecture where the URL parameters are still an abstract concept. Maybe I missed something that makes this abstract use possible. If so, please let me know! If not, this would need to be fixed IMO, to make crossroads applicable as a routing library in more complex routing systems.

-- Freddy Snijder