airbnb/rendr — pull request #145 by bigethan (2013-10-16 06:49:20+00:00)
Title: Adding checks for routes using regexes.

the routes still need to be prepared a bit due to express using a leading `/` and backbone
not using the leading slash. I went with using backbone regexes as things are more of a Backbone app than an express app. Though even with this change, the routes file has some logic, like so:

```
//app/routes.js
//backbone style regex, no leading slash
var routes =
[
['', 'getHome', 'home#index'],
[/^foo.*/, 'getFoo', 'foo#index'],
[/^bar.*/, 'getBar', 'bar#index']
];

module.exports = function(match) {
routes.forEach( function(el, i){
pattern = el[0];
if(el[0] instanceof RegExp) {
if(this.isServer) {
//add the leading / for express if the regex is looking at the start of the path
pattern = new RegExp(routeArray[0].toString().slice(1,-1).replace(/^\^/, '^\\\/'));
}
}
match(pattern, el[1], el[2]);
});
};
```

This logic could be moved into the buildRoutes:captureRoutes method:

```
//rendr/shared/base/router.js

function captureRoutes() {
var routeArray = _.toArray(arguments);

if(routeArray[0] instanceof RegExp) {
if(this.isServer) {
//add the leading / for express if the regex is looking at the start of the path
routeArray[0] = new RegExp(routeArray[0].toString().slice(1,-1).replace(/^\^/, '^\\\/'));
}
}
routes.push(routeArray);
}
```

but didn't want to suggest too much, plus this feels juuust a little weird.

Happy to update with the `captureRoutes` change if you see fit, or discuss other ways to allow for a richer routing/url matching than backbone allows via :params, splats, etc.