无法导航到另一个屏幕反应本地

问题描述:

我已经使用POST API进行登录身份验证,我收到成功响应,在成功响应,我只是想导航到其他屏幕说例如(从登录屏幕到视频屏幕) 。但它不适合我,请查看我的代码并告诉我我犯了什么错误。无法导航到另一个屏幕反应本地

index.android.js: 
    export default class Registration extends Component { 
    render() { 
    const { navigation } =this.props; 
    return (
    <Login navigation={ navigation }/>); 
    } 
    } 

src/Login.js: 

class Login extends Component { 
constructor(props) { 
    super(props); 
    this.redirect=this.redirect.bind(this) 
    this.state = { 
     email: '', 
     password: '', 
     errors: '', 
     } 
    } 
    On button submit i just calling below method 
    CallSignIn() { 
    fetch("http://localhost:3000/users/login", { method: "POST", body: JSON.stringify({ email: this.state.email, password: this.state.password }), headers: { 'x-api-key': '7LH9ElCr4p1GLiMXAWLu0a9UsvKZ4wJr7t1N3ewh', 'Content-Type': 'application/json' } }) 
     .then((response) => response.json()) 
     .then((responseData) => { 
      this.setState({ showProgress: false }) 
      this.redirect() 
     Alert.alert("success:", JSON.stringify(responseData.token)); 
     }) 
     .done(); 
     } 
redirect() { 
const { navigate } = props.navigation; 
    navigate('Videos') 
} 
} 
+0

看看这个,它可以帮助你,https://*.com/questions/43682601/undefined -navigator-push-react-native-0-43-4/43739206#43739206 – Akram

+0

谢谢我正在使用最新版本的反应,现在已弃用。 – saiRam89

+0

显示您的StackNavigator代码。 –

在您登录组件访问导航对象const { navigate } =this.props.navigation;

与此相反const { navigate } = props.navigation;

+0

yes试过之前把'.catch((e)=> {console.log(e)})'试一下也显示找不到可变道具 – saiRam89

+0

尝试绑定重定向函数对此...因此,您将它称为'this.redirect.bind(this)' –

+0

或者您可以将其绑定在构造函数 –