diff --git a/modules/components/Route.js b/modules/components/Route.js index 961dc413bf..5faa495133 100644 --- a/modules/components/Route.js +++ b/modules/components/Route.js @@ -1,7 +1,7 @@ var React = require('react'); var Configuration = require('../Configuration'); var PropTypes = require('../PropTypes'); - +var RouteHandler = require('./RouteHandler'); /** * components specify components that are rendered to the page when the * URL matches a given pattern. @@ -39,6 +39,8 @@ var PropTypes = require('../PropTypes'); * ); * } * }); + * + * If no handler is provided for the route, it will render a matched child route. */ var Route = React.createClass({ @@ -49,8 +51,14 @@ var Route = React.createClass({ propTypes: { name: PropTypes.string, path: PropTypes.string, - handler: PropTypes.func.isRequired, + handler: PropTypes.func, ignoreScrollBehavior: PropTypes.bool + }, + + getDefaultProps: function(){ + return { + handler: RouteHandler + }; } }); diff --git a/modules/components/__tests__/Route-test.js b/modules/components/__tests__/Route-test.js new file mode 100644 index 0000000000..623387fdf5 --- /dev/null +++ b/modules/components/__tests__/Route-test.js @@ -0,0 +1,38 @@ +var expect = require('expect'); +var React = require('react'); +var Router = require('../../index'); +var DefaultRoute = require('../DefaultRoute'); +var Route = require('../Route'); +var { Foo, Bar } = require('../../utils/TestHandlers'); + +describe('Route', function () { + + it('renders default child route if path match but no handler provided', function () { + var routes = ( + + + + + ); + + Router.run(routes, '/', function (App) { + var html = React.renderToString(); + expect(html).toMatch(/Foo/); + }); + }); + + it('renders matched child route if no handler provided', function () { + var routes = ( + + + + + ); + + Router.run(routes, '/bar', function (App) { + var html = React.renderToString(); + expect(html).toMatch(/Bar/); + }); + }); + +});