Skip to content

Commit fdc9967

Browse files
committed
Do not allow children to be passed to activeRouteHandler
1 parent ebf54ab commit fdc9967

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

modules/components/Route.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,10 @@ function computeHandlerProps(matches, query) {
466466
}
467467

468468
childHandler = function (props, addedProps) {
469-
var children = Array.prototype.slice.call(arguments, 2);
470-
return route.props.handler.apply(null, [ mergeProperties(props, addedProps) ].concat(children));
469+
if (arguments.length > 2 && typeof arguments[2] !== 'undefined')
470+
throw new Error('Passing children to a route handler is not supported');
471+
472+
return route.props.handler.apply(null, mergeProperties(props, addedProps));
471473
}.bind(this, props);
472474
});
473475

specs/Route.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ describe('a Route with custom props', function() {
112112
});
113113
});
114114

115+
describe('a route handler', function () {
116+
it('may not receive children', function (done) {
117+
var InvalidHandler = React.createClass({
118+
displayName: 'InvalidHandler',
119+
render: function () {
120+
try {
121+
var result = this.props.activeRouteHandler({}, React.DOM.div());
122+
assert(false, 'activeRouteHandler rendered with children');
123+
return result;
124+
} catch (error) {
125+
assert(error);
126+
}
127+
128+
done();
129+
}
130+
});
131+
132+
var route = TestUtils.renderIntoDocument(
133+
Route({ handler: InvalidHandler },
134+
Route({ path: '/home', handler: App })
135+
)
136+
);
137+
138+
route.dispatch('/home');
139+
});
140+
});
141+
115142
describe('a Route', function() {
116143
it('requires a handler');
117144
});

0 commit comments

Comments
 (0)