Skip to content

Commit

Permalink
Fix race condition in CaptureClicks. Fixes #176
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Jul 12, 2016
1 parent 0d7b1e3 commit e453e24
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/CaptureClicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,25 @@ var CaptureClicks = React.createClass({
el.blur();
e.preventDefault();

// flag if we already found a "not found" case and bailed
var bail = false;
// Mark if any of our routers matched. If they didn't, we'll call gotoURL.
var matched = false;

var onBeforeNavigation = function(path, navigation, match) {
if (bail) {
return false;
} else if (!match || !match.match) {
bail = true;
this.props.gotoURL(el.href);
return false;
if (match && match.match) {
matched = true;
}
}.bind(this);
}

var gotoURL = this.props.gotoURL;
this.props.environment.navigate(
url.pathname + (url.hash.length > 1 ? url.hash : ''),
{onBeforeNavigation: onBeforeNavigation},
function(err, info) {
if (err) {
throw err;
}
// No routers matched - so we'll escape out using gotoURL.
if (!matched) gotoURL(el.href);
});
},

Expand Down

0 comments on commit e453e24

Please sign in to comment.