我有一个带有以下代码的反应应用程序:
import { Link } from 'react-router';
var Matches = React.createClass({
contextTypes: {
router: React.PropTypes.object
},
...
componentWillMount: function() {
var router = this.context.router;
...
router.push('/pay');
}
});
出于某种原因,当我尝试去“/ pay”时,我得到以下例外:
"Uncaught ReferenceError: Link is not defined"
我的路线定义如下:
var auth_and_info_check = function auth_and_info_check(nextState, replace, callback) {
if (!_horizon_connect2.default.hasAuthToken() && !nextState.location.pathname.endsWith("login")) {
replace({ pathname: '/login' });
callback();
} else if (_horizon_connect2.default.hasAuthToken() && nextState.location.pathname.endsWith("/")) {
_horizon_connect2.default.currentUser().fetch().subscribe(function (user) {
if (!(user.hasOwnProperty('data') && user.data.hasOwnProperty('phone'))) {
replace({ pathname: '/user_info' });
callback();
} else {
callback();
}
});
} else {
callback(); //In my case after routing "/pay" I call this callback
}
};
<Router history={hashHistory}>
<Route component={Layout}>
...
<Route path="/pay" component={Pay} onEnter={auth_and_info_check}/>
...
</Router>
</Router>
你知道我做错了什么吗?
答案 0 :(得分:0)
从'react-router-dom'
导入{Link}工作正常