Skip to content

Commit f7d63ac

Browse files
committed
Add <Router routes> alias
1 parent 3ab84b4 commit f7d63ac

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

modules/Router.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export var Router = React.createClass({
8787

8888
propTypes: {
8989
history: history.isRequired,
90-
children: routes.isRequired,
90+
children: routes,
91+
routes, // Alias for children
9192
createElement: func.isRequired,
9293
onError: func.isRequired,
9394
onUpdate: func,
@@ -122,7 +123,7 @@ export var Router = React.createClass({
122123
_updateState(location) {
123124
invariant(
124125
Location.isLocation(location),
125-
'Router needs a valid Location'
126+
'A <Router> needs a valid Location'
126127
);
127128

128129
this.nextLocation = location;
@@ -261,9 +262,14 @@ export var Router = React.createClass({
261262
},
262263

263264
componentWillMount() {
264-
var { children, history } = this.props;
265+
var { history, routes, children } = this.props;
265266

266-
this.routes = createRoutes(children);
267+
invariant(
268+
routes || children,
269+
'A <Router> needs some routes'
270+
);
271+
272+
this.routes = createRoutes(routes || children);
267273
this.transitionHooks = [];
268274
this.nextLocation = null;
269275

@@ -292,8 +298,11 @@ export var Router = React.createClass({
292298
'<Router history> may not be changed'
293299
);
294300

295-
if (this.props.children !== nextProps.children) {
296-
this.routes = createRoutes(nextProps.children);
301+
var currentRoutes = this.props.routes || this.props.children;
302+
var nextRoutes = nextProps.routes || nextProps.children;
303+
304+
if (currentRoutes !== nextRoutes) {
305+
this.routes = createRoutes(nextRoutes);
297306

298307
// Call this here because _updateState
299308
// uses this.routes to determine state.

0 commit comments

Comments
 (0)