@@ -38,10 +38,8 @@ var RouteStore = {
3838 * Registers a <Route> and all of its children with the store. Also,
3939 * does some normalization and validation on route props.
4040 */
41- registerRoute : function ( route , _parentRoute ) {
42- // Note: When route is a top-level route, _parentRoute
43- // is actually a <Routes>, not a <Route>. We do this so
44- // <Routes> can get a defaultRoute like <Route> does.
41+ registerRoute : function ( route , parentRoute ) {
42+ // Note: parentRoute may be a <Route> _or_ a <Routes>.
4543 var props = route . props ;
4644
4745 invariant (
@@ -55,21 +53,21 @@ var RouteStore = {
5553
5654 if ( props . path || props . name ) {
5755 props . path = Path . normalize ( props . path || props . name ) ;
58- } else if ( _parentRoute && _parentRoute . props . path ) {
59- props . path = _parentRoute . props . path ;
56+ } else if ( parentRoute && parentRoute . props . path ) {
57+ props . path = parentRoute . props . path ;
6058 } else {
6159 props . path = '/' ;
6260 }
6361
6462 props . paramNames = Path . extractParamNames ( props . path ) ;
6563
6664 // Make sure the route's path has all params its parent needs.
67- if ( _parentRoute && Array . isArray ( _parentRoute . props . paramNames ) ) {
68- _parentRoute . props . paramNames . forEach ( function ( paramName ) {
65+ if ( parentRoute && Array . isArray ( parentRoute . props . paramNames ) ) {
66+ parentRoute . props . paramNames . forEach ( function ( paramName ) {
6967 invariant (
7068 props . paramNames . indexOf ( paramName ) !== - 1 ,
7169 'The nested route path "%s" is missing the "%s" parameter of its parent path "%s"' ,
72- props . path , paramName , _parentRoute . props . path
70+ props . path , paramName , parentRoute . props . path
7371 ) ;
7472 } ) ;
7573 }
@@ -87,28 +85,36 @@ var RouteStore = {
8785 _namedRoutes [ props . name ] = route ;
8886 }
8987
90- if ( _parentRoute && isDefault ) {
88+ if ( parentRoute && isDefault ) {
9189 invariant (
92- _parentRoute . props . defaultRoute == null ,
90+ parentRoute . props . defaultRoute == null ,
9391 'You may not have more than one <DefaultRoute> per <Route>'
9492 ) ;
9593
96- _parentRoute . props . defaultRoute = route ;
94+ parentRoute . props . defaultRoute = route ;
9795
9896 return null ;
9997 }
10098
101- // Make sure children is an array, excluding <DefaultRoute>s .
102- var children = [ ] ;
99+ // Make sure children is an array.
100+ props . children = RouteStore . registerChildren ( props . children , route ) ;
103101
104- React . Children . forEach ( props . children , function ( child ) {
105- if ( child = RouteStore . registerRoute ( child , route ) )
106- children . push ( child ) ;
107- } ) ;
102+ return route ;
103+ }
104+
105+ /**
106+ * Registers many children routes at once, always returning an array.
107+ */
108+ registerChildren : function ( children , parentRoute ) {
109+ var routes = [ ] ;
108110
109- props . children = children ;
111+ React . Children . forEach ( children , function ( child ) {
112+ // Exclude <DefaultRoute>s.
113+ if ( child = RouteStore . registerRoute ( child , parentRoute ) )
114+ routes . push ( child ) ;
115+ } ) ;
110116
111- return route ;
117+ return routes ;
112118 } ,
113119
114120 /**
0 commit comments