Skip to content

Commit

Permalink
[fixed] Ignore falsy routes
Browse files Browse the repository at this point in the history
Routes which are null/undefined should be skipped
in the React.Children traversal when creating routes.
This makes the Router's behavior closer match React
in handling empty elements.
  • Loading branch information
tgriesser committed Jan 20, 2015
1 parent 5fa86d5 commit 84056ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions tests/Router-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,20 @@ describe('Router.run', function () {
});
});

it('does not break on falsy routes', function (done) {
var routes = [
<Route handler={Foo} path="/foo"/>,
null,
<Route handler={Bar} path="/bar"/>,
undefined
];
Router.run(routes, '/foo', function (Handler, state) {
var html = React.renderToString(<Handler/>);
expect(html).toMatch(/Foo/);
done();
});
});

it('matches nested routes', function (done) {
var routes = (
<Route handler={Nested} path='/'>
Expand Down
4 changes: 2 additions & 2 deletions utils/createRoutesFromChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ function createRoutesFromChildren(children, parentRoute, namedRoutes) {
var routes = [];

React.Children.forEach(children, function (child) {
// Exclude <DefaultRoute>s and <NotFoundRoute>s.
if (child = createRoute(child, parentRoute, namedRoutes))
// Exclude null values, <DefaultRoute>s and <NotFoundRoute>s.
if (child && (child = createRoute(child, parentRoute, namedRoutes)))
routes.push(child);
});

Expand Down

0 comments on commit 84056ba

Please sign in to comment.