Skip to content

Commit 6b9982c

Browse files
committed
Added initialPath and initialMatches to <Routes>
These are currently only used for server-side rendering.
1 parent 6482225 commit 6b9982c

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

modules/components/Routes.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ var warning = require('react/lib/warning');
33
var invariant = require('react/lib/invariant');
44
var copyProperties = require('react/lib/copyProperties');
55
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');
610
var reversedArray = require('../utils/reversedArray');
711
var Transition = require('../utils/Transition');
812
var Redirect = require('../utils/Redirect');
@@ -158,11 +162,6 @@ function returnNull() {
158162
return null;
159163
}
160164

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-
166165
/**
167166
* The <Routes> component configures the route hierarchy and renders the
168167
* route matching the current location when rendered into a document.
@@ -173,16 +172,26 @@ var Routes = React.createClass({
173172

174173
displayName: 'Routes',
175174

176-
mixins: [ ActiveContext, LocationContext, RouteContext, ScrollContext ],
175+
mixins: [ RouteContext, ActiveContext, LocationContext, ScrollContext ],
177176

178177
propTypes: {
178+
initialPath: React.PropTypes.string.isRequired,
179+
initialMatches: React.PropTypes.array.isRequired,
179180
onChange: React.PropTypes.func,
180181
onError: React.PropTypes.func
181182
},
182183

184+
getDefaultProps: function () {
185+
return {
186+
initialPath: '/',
187+
initialMatches: []
188+
};
189+
},
190+
183191
getInitialState: function () {
184192
return {
185-
matches: []
193+
path: this.props.initialPath,
194+
matches: this.props.initialMatches
186195
};
187196
},
188197

@@ -204,7 +213,8 @@ var Routes = React.createClass({
204213
* { route: <PostRoute>, params: { id: '123' } } ]
205214
*/
206215
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);
208218
},
209219

210220
updateLocation: function (path, actionType) {
@@ -214,7 +224,7 @@ var Routes = React.createClass({
214224
if (this.state.path)
215225
this.recordScroll(this.state.path);
216226

217-
this.dispatch(path, actionType, function (error, abortReason) {
227+
this.dispatch(path, function (error, abortReason, nextState) {
218228
if (error) {
219229
if (this.props.onError) {
220230
this.props.onError.call(this, error);

0 commit comments

Comments
 (0)