millermedeiros / crossroads.js

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

remove greedy routes support or disable it by default? #68

Open millermedeiros opened 12 years ago

millermedeiros commented 12 years ago

Greedy routes aren't that common and the way it is currently implemented degrades the performance of the router if they are enabled (since it loops through all the routes even if it already matched another route) so it makes sense to remove this feature or at least disable it by default (crossroads.greedyEnabled = false).

I feel that greedy routes makes the router logic more complex than needed and I can't remember the last time I needed this feature on a real app. I feel that "chaining" multiple routers is more than enough in most cases and also a better approach:

var greedyRouter = crossroads.create();

// "pipe" routers
crossroads.routed.add(function(request){
  greedyRouter.parse(request);
});

greedyRouter.addRoute('foo/{rest*}', doFoo);
greedyRouter.addRoute('bar/{rest*}', doBar);

The only problem on removing this feature is that I think some people are using it (based on #46 and a couple other comments). Maybe this should be a change for v1.0.0 since it's a breaking change. Will probably wait a few weeks to think about it better and wait for feedback... Maybe do the changes on a separate branch to check if it will really reduce complexity.