我已經使用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')
}
}
看看這個,它可以幫助你,https://stackoverflow.com/questions/43682601/undefined -navigator-push-react-native-0-43-4/43739206#43739206 – Akram
謝謝我正在使用最新版本的反應,現在已棄用。 – saiRam89
顯示您的StackNavigator代碼。 –