2017-06-22 91 views
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') 
} 
} 
+0

看看這個,它可以幫助你,https://stackoverflow.com/questions/43682601/undefined -navigator-push-react-native-0-43-4/43739206#43739206 – Akram

+0

謝謝我正在使用最新版本的反應,現在已棄用。 – saiRam89

+0

顯示您的StackNavigator代碼。 –

回答

0

在您登錄組件訪問導航對象const { navigate } =this.props.navigation;

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

+0

yes試過之前把'.catch((e)=> {console.log(e)})'試一下也顯示找不到可變道具 – saiRam89

+0

嘗試綁定重定向函數對此...因此,您將它稱爲'this.redirect.bind(this)' –

+0

或者您可以將其綁定在構造函數 –

相關問題