@@ -3,6 +3,10 @@ var warning = require('react/lib/warning');
3
3
var invariant = require ( 'react/lib/invariant' ) ;
4
4
var copyProperties = require ( 'react/lib/copyProperties' ) ;
5
5
var HashLocation = require ( '../locations/HashLocation' ) ;
6
+ var ActiveContext = require ( '../mixins/ActiveContext' ) ;
7
+ var LocationContext = require ( '../mixins/LocationContext' ) ;
8
+ var RouteContext = require ( '../mixins/RouteContext' ) ;
9
+ var ScrollContext = require ( '../mixins/ScrollContext' ) ;
6
10
var reversedArray = require ( '../utils/reversedArray' ) ;
7
11
var Transition = require ( '../utils/Transition' ) ;
8
12
var Redirect = require ( '../utils/Redirect' ) ;
@@ -158,11 +162,6 @@ function returnNull() {
158
162
return null ;
159
163
}
160
164
161
- var ActiveContext = require ( '../mixins/ActiveContext' ) ;
162
- var LocationContext = require ( '../mixins/LocationContext' ) ;
163
- var RouteContext = require ( '../mixins/RouteContext' ) ;
164
- var ScrollContext = require ( '../mixins/ScrollContext' ) ;
165
-
166
165
/**
167
166
* The <Routes> component configures the route hierarchy and renders the
168
167
* route matching the current location when rendered into a document.
@@ -173,16 +172,26 @@ var Routes = React.createClass({
173
172
174
173
displayName : 'Routes' ,
175
174
176
- mixins : [ ActiveContext , LocationContext , RouteContext , ScrollContext ] ,
175
+ mixins : [ RouteContext , ActiveContext , LocationContext , ScrollContext ] ,
177
176
178
177
propTypes : {
178
+ initialPath : React . PropTypes . string . isRequired ,
179
+ initialMatches : React . PropTypes . array . isRequired ,
179
180
onChange : React . PropTypes . func ,
180
181
onError : React . PropTypes . func
181
182
} ,
182
183
184
+ getDefaultProps : function ( ) {
185
+ return {
186
+ initialPath : '/' ,
187
+ initialMatches : [ ]
188
+ } ;
189
+ } ,
190
+
183
191
getInitialState : function ( ) {
184
192
return {
185
- matches : [ ]
193
+ path : this . props . initialPath ,
194
+ matches : this . props . initialMatches
186
195
} ;
187
196
} ,
188
197
@@ -204,7 +213,8 @@ var Routes = React.createClass({
204
213
* { route: <PostRoute>, params: { id: '123' } } ]
205
214
*/
206
215
match : function ( path ) {
207
- return findMatches ( Path . withoutQuery ( path ) , this . getRoutes ( ) , this . props . defaultRoute , this . props . notFoundRoute ) ;
216
+ var routes = this . getRoutes ( ) ;
217
+ return findMatches ( Path . withoutQuery ( path ) , routes , this . props . defaultRoute , this . props . notFoundRoute ) ;
208
218
} ,
209
219
210
220
updateLocation : function ( path , actionType ) {
@@ -214,7 +224,7 @@ var Routes = React.createClass({
214
224
if ( this . state . path )
215
225
this . recordScroll ( this . state . path ) ;
216
226
217
- this . dispatch ( path , actionType , function ( error , abortReason ) {
227
+ this . dispatch ( path , function ( error , abortReason , nextState ) {
218
228
if ( error ) {
219
229
if ( this . props . onError ) {
220
230
this . props . onError . call ( this , error ) ;
0 commit comments