2017-06-22 29 views
0

POST APIを使用してログイン認証を行いました。成功応答内で成功応答を受信しました。たとえば、ログイン画面からビデオ画面に移動するなど、私のコードを見て、私がどこでミスをしたか教えてください。 const { navigate } =this.props.navigation;反応ネイティブの別の画面にナビゲートできません

としてログインコンポーネントのアクセスナビゲーションオブジェクトで

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 } = props.navigation;

+0

yesまた、表示可能な小道具が見つからないことを試みた – saiRam89

+0

リダイレクト機能これを... this.redirect.bind(this) ' –

+0

として呼び出すか、それをコンストラクタでバインドすることができます –

関連する問題