Skip to content

Commit 0bb04d1

Browse files
committed
Re-use existing match objects
1 parent 97dbf2d commit 0bb04d1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

modules/components/Routes.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ var Routes = React.createClass({
8484

8585
getInitialState: function () {
8686
return {
87+
matches: [],
8788
routes: RouteStore.registerChildren(this.props.children, this)
8889
};
8990
},
@@ -270,7 +271,7 @@ function computeNextState(routes, transition, callback) {
270271
nextMatches = [];
271272

272273
var fromMatches, toMatches;
273-
if (currentMatches) {
274+
if (currentMatches.length) {
274275
updateMatchComponents(currentMatches, routes.refs);
275276

276277
fromMatches = currentMatches.filter(function (match) {
@@ -295,17 +296,19 @@ function computeNextState(routes, transition, callback) {
295296
if (error || transition.isAborted)
296297
return callback(error);
297298

298-
var rootMatch = getRootMatch(nextMatches);
299+
var matches = currentMatches.slice(0, -fromMatches.length).concat(toMatches);
300+
var rootMatch = getRootMatch(matches);
299301
var params = (rootMatch && rootMatch.params) || {};
302+
var routes = matches.map(function (match) {
303+
return match.route;
304+
});
300305

301306
callback(null, {
302307
path: transition.path,
303-
matches: nextMatches,
308+
matches: matches,
309+
activeRoutes: routes,
304310
activeParams: params,
305-
activeQuery: query,
306-
activeRoutes: nextMatches.map(function (match) {
307-
return match.route;
308-
})
311+
activeQuery: query
309312
});
310313
});
311314
});

0 commit comments

Comments
 (0)