Skip to content

Commit f51d6f0

Browse files
committed
Fix for a single route
this.children isn't an array
1 parent 85f9ce3 commit f51d6f0

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Diff for: index.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ function createRouter(component) {
3737
var match, page, notFound;
3838
var len, i;
3939

40-
for (i = 0, len = this.props.children.length; i < len; i++) {
41-
var current = this.props.children[i];
40+
var children = this.props.children;
41+
42+
if (!Array.isArray(children)) {
43+
children = [children];
44+
}
45+
46+
for (i = 0, len = children.length; i < len; i++) {
47+
var current = children[i];
4248

4349
if (process.env.NODE_ENV !== "production") {
4450
invariant(
4551
current.handler !== undefined && current.path !== undefined,
46-
"Router should contain either Route or NotFound components as children")
52+
"Router should contain either Route or NotFound components " +
53+
"as children")
4754
}
4855

4956
if (current.path) {
@@ -60,11 +67,11 @@ function createRouter(component) {
6067
}
6168
}
6269

63-
var handler = page ? page.handler :
64-
notFound ? notFound.handler :
70+
var rendered = page ? page.handler(match) :
71+
notFound ? notFound.handler(match) :
6572
[];
6673

67-
return this.transferPropsTo(component(null, handler(match)));
74+
return this.transferPropsTo(component(null, rendered));
6875
}
6976
});
7077
}

0 commit comments

Comments
 (0)