rackt/react-router — pull request #382 by rpflorence (2014-10-10 19:16:15+00:00)
Title: [added] ServerRendering.matchRoutes

This method allows people on the server to use the router as simply a router that matches their route descriptors, and not something that emits a react view.

Its common for a server to emit both HTML and JSON, depending the `Accept` header. We have an opportunity here to encourage the use of the router for these kinds of servers, instead of making the decision to use react router more difficult by requiring a separate routing mechanism for emitting json (or other types of data).

Imagine something like this on the server:

```js
handleReqeuest(function(req, res) {
var requestType = getRequestType(req);
if (requestType === 'json')
Router.matchRoutes(routes, req.path, function(err, abortReason, state) {
// devs could add a static `getJSON` to handlers to represent their url as json
var deepestHandler = state.matches.reverse()[0].route.props.handler
deepestHandler.getJSON(function(json) {
res.json(json);
});
});
else if (requestType === 'html')
Router.renderRoutesToString(routes, req.path, function(err, abortReason, html) {
res.send(html);
});
});
```