首页 文章

无法在本机反应中导航到另一个屏幕

提问于
浏览
0

我已经使用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')
}
}

1 回答

  • 0

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

    而不是这个 const { navigate } = props.navigation;

相关问题