Skip to content

Commit e453e24

Browse files
committed
Fix race condition in CaptureClicks. Fixes #176
1 parent 0d7b1e3 commit e453e24

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/CaptureClicks.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,25 @@ var CaptureClicks = React.createClass({
101101
el.blur();
102102
e.preventDefault();
103103

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

107107
var onBeforeNavigation = function(path, navigation, match) {
108-
if (bail) {
109-
return false;
110-
} else if (!match || !match.match) {
111-
bail = true;
112-
this.props.gotoURL(el.href);
113-
return false;
108+
if (match && match.match) {
109+
matched = true;
114110
}
115-
}.bind(this);
111+
}
116112

113+
var gotoURL = this.props.gotoURL;
117114
this.props.environment.navigate(
118115
url.pathname + (url.hash.length > 1 ? url.hash : ''),
119116
{onBeforeNavigation: onBeforeNavigation},
120117
function(err, info) {
121118
if (err) {
122119
throw err;
123120
}
121+
// No routers matched - so we'll escape out using gotoURL.
122+
if (!matched) gotoURL(el.href);
124123
});
125124
},
126125

0 commit comments

Comments
 (0)