@@ -38,10 +38,8 @@ var RouteStore = {
38
38
* Registers a <Route> and all of its children with the store. Also,
39
39
* does some normalization and validation on route props.
40
40
*/
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>.
45
43
var props = route . props ;
46
44
47
45
invariant (
@@ -55,21 +53,21 @@ var RouteStore = {
55
53
56
54
if ( props . path || props . name ) {
57
55
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 ;
60
58
} else {
61
59
props . path = '/' ;
62
60
}
63
61
64
62
props . paramNames = Path . extractParamNames ( props . path ) ;
65
63
66
64
// 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 ) {
69
67
invariant (
70
68
props . paramNames . indexOf ( paramName ) !== - 1 ,
71
69
'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
73
71
) ;
74
72
} ) ;
75
73
}
@@ -87,28 +85,36 @@ var RouteStore = {
87
85
_namedRoutes [ props . name ] = route ;
88
86
}
89
87
90
- if ( _parentRoute && isDefault ) {
88
+ if ( parentRoute && isDefault ) {
91
89
invariant (
92
- _parentRoute . props . defaultRoute == null ,
90
+ parentRoute . props . defaultRoute == null ,
93
91
'You may not have more than one <DefaultRoute> per <Route>'
94
92
) ;
95
93
96
- _parentRoute . props . defaultRoute = route ;
94
+ parentRoute . props . defaultRoute = route ;
97
95
98
96
return null ;
99
97
}
100
98
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 ) ;
103
101
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 = [ ] ;
108
110
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
+ } ) ;
110
116
111
- return route ;
117
+ return routes ;
112
118
} ,
113
119
114
120
/**
0 commit comments