Skip to content

Commit a64d0cd

Browse files
committed
Use component in willTransitionFrom, not descriptor
Fixes #47
1 parent 63bdab2 commit a64d0cd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

modules/components/Route.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ var Route = React.createClass({
212212
},
213213

214214
render: function () {
215-
return this.props.handler(this.state.handlerProps);
215+
return this.props.handler(computeHandlerProps(this.state.matches || [], this.state.query));
216216
}
217217

218218
});
@@ -341,7 +341,7 @@ function syncWithTransition(route, transition) {
341341
toMatches = nextMatches;
342342
}
343343

344-
return checkTransitionFromHooks(fromMatches, transition).then(function () {
344+
return checkTransitionFromHooks(fromMatches, route.refs, transition).then(function () {
345345
if (transition.isCancelled)
346346
return; // No need to continue.
347347

@@ -355,7 +355,6 @@ function syncWithTransition(route, transition) {
355355
var state = {
356356
path: transition.path,
357357
matches: nextMatches,
358-
handlerProps: computeHandlerProps(nextMatches, query),
359358
activeParams: params,
360359
activeQuery: query,
361360
activeRoutes: nextMatches.map(function (match) {
@@ -376,15 +375,15 @@ function syncWithTransition(route, transition) {
376375
* the route's handler, so that the deepest nested handlers are called first.
377376
* Returns a promise that resolves after the last handler.
378377
*/
379-
function checkTransitionFromHooks(matches, transition) {
378+
function checkTransitionFromHooks(matches, refs, transition) {
380379
var promise = Promise.resolve();
381380

382381
reversedArray(matches).forEach(function (match) {
383382
promise = promise.then(function () {
384383
var handler = match.route.props.handler;
385384

386385
if (!transition.isCancelled && handler.willTransitionFrom)
387-
return handler.willTransitionFrom(transition, match.handlerInstance);
386+
return handler.willTransitionFrom(transition, refs[match.refName]);
388387
});
389388
});
390389

@@ -417,31 +416,33 @@ function checkTransitionToHooks(matches, transition) {
417416
*/
418417
function computeHandlerProps(matches, query) {
419418
var props = {
419+
ref: null,
420420
key: null,
421421
params: null,
422422
query: null,
423423
activeRoute: null
424424
};
425425

426-
var previousMatch;
427-
reversedArray(matches).forEach(function (match) {
426+
var childDescriptor;
427+
reversedArray(matches).forEach(function (match, index) {
428428
var route = match.route;
429429

430430
props = Route.getUnreservedProps(route.props);
431431

432+
props.ref = 'route-' + index;
432433
props.key = Path.injectParams(route.props.path, match.params);
433434
props.params = match.params;
434435
props.query = query;
435436

436-
if (previousMatch) {
437-
props.activeRoute = previousMatch.handlerInstance;
437+
if (childDescriptor) {
438+
props.activeRoute = childDescriptor;
438439
} else {
439440
props.activeRoute = null;
440441
}
441442

442-
match.handlerInstance = route.props.handler(props);
443+
childDescriptor = route.props.handler(props);
443444

444-
previousMatch = match;
445+
match.refName = props.ref;
445446
});
446447

447448
return props;

0 commit comments

Comments
 (0)