React Navigation is not working in an axios call in react native

Viewed 1078

I am trying to navigate the user towards home screen but my navigation is not working. Its showing alert of login successful but not navigating towards home screen here is my code...

 axios.post('/api_workreap/wp-json/api/v1/user/do_login', {
        username: username,
        password: password
          })
          .then((response) => {
            console.log(JSON.stringify(response.data.type));
            if(response.data.type == "success"){
              alert("Login Successfully");
              // this.props.navigation.navigate("/src/Home/home.js");
              NavigationActions.navigate({ routeName: 'home' })
            }else if(response.data.type == "error"){
              alert("Incorrect Detail");
            }
        })
          .catch((error) => {
            console.log( JSON.stringify(response));
          });
1 Answers

you can try this, basically create your own navigation service on top of your navigation router, tutorial is pretty straight forward.

Related