0
我试图重定向我的用户,当他的登录成功,但我得到这个错误:“未定义不是一个对象(评估'_this2.props.navigation')”React Native,导航:“未定义不是一个对象”
这是我在App.js代码:
const Homepage = StackNavigator({
Home: {screen: Home},
Store: {screen: Store},
Admin: {screen: Admin},
});
这是我在Store.js代码,我尝试将用户重定向一旦他登录:
<Button style={{color:'gray', borderColor: 'gray'}} onPress={() =>
this.login()} title="Me connecter" />
login(){
firebase.auth().signInWithEmailAndPassword(this.state.emailLogin,
this.state.passwordLogin).then(function(user) {
// Send the user to the next step
setTimeout(() => {
const { navigate } = this.props.navigation;
navigate('Admin');
}, 1500);
}).catch(function(error) {
console.log('error');
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
});
}
在此先感谢为您的时间和宝贵的答案。
这两个函数都必须绑定这个或箭头函数。我的意思是setTimeout的函数也应该绑定。 – Kyon
@Kyon'setTimeout'已经是一个箭头功能,如果我看得很对 – bennygenel
好吧,你是对的! – Kyon