Mar*_*zyż 3 reactjs react-router
当我尝试将路由器传递给组件时,我收到了这样的错误:
class Login extends React.Component {
onClick(){
Actions.login(this.context.router);
}
static contextTypes = {
router: React.PropTypes.func.isRequired
}
render(){
return (
<Card style={{
'maxWidth': '800px',
'margin': '30px auto',
'padding': '50px'
}}>
<CardText style={{
'textAlign': 'center'
}}>
To start chatting away, please log in with your Google account.
</CardText>
<RaisedButton style={{
display: 'block',
}} onClick={this.onClick.bind(this)}
label="Log in with Google" primary={true} />
</Card>
);
}
}
export default Login;
Run Code Online (Sandbox Code Playgroud)
然后我尝试将其传递给操作login,以便在记录后重定向到另一条路径.行动登录:
login(router){
return (dispatch) => {
let firebaseRef = new Firebase('https://front-react-stack.firebaseio.com');
firebaseRef.authWithOAuthPopup("google", (error, user) => {
if(error){
return;
}
dispatch(user);
router.push('/chat');
});
}
Run Code Online (Sandbox Code Playgroud)
}
但是在登录控制台后出现错误:"警告:失败的上下文类型:提供router的类型的上下文无效,预期.检查渲染方法."objectLoginfunctionRouterContext
在我看来,我已经过去了func.不是一个object类型所以我不知道这个错误来自哪里...
router是一个对象:
试试这个:
static contextTypes = {
router: React.PropTypes.object.isRequired
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1566 次 |
| 最近记录: |