Перенаправление после отправки формы React Native - PullRequest
0 голосов
/ 28 мая 2020

У меня простая форма подключения, я хочу, чтобы мой пользователь был перенаправлен на мою домашнюю страницу после подключения. action в моей форме, похоже, не работает, поскольку URL-адрес не меняется после отправки формы.

Вот содержимое моего Login class в моем Login.tsx файле

constructor(props) {
    super(props);
    this.state = {
      email: "",
      password: ""
    }
  }

  handleSubmit() {
    const email = this.state.email;
    console.log(email);
    const password = this.state.password;
    console.log(password);
    axios.post("http://snapi.epitech.eu/connection", { email, password } 
        ).then(reponse => {
            console.log('connect', reponse);
        }).catch(error => {
            console.log('error', error);
    });

}

  render() {
    //const { dataSource, fromFetch, fromAxios, loading, axiosData } = this.state
    return (
    <View style={styles.container}>
      <Text>Connection</Text>
      <form onSubmit={ this.handleSubmit }
            action="localhost:19006/home">
        <label>email</label>
        <TextInput 
          //name="email"
          style={styles.input}
          value={ this.state.email } 
          onChangeText={ email => this.setState({email}) } 
          //onChange={val => this.onChange('email', val)}
        />
        <label>password</label>
        <TextInput 
          style={styles.input}
          secureTextEntry={true}
          value={ this.state.password } 
          onChangeText={ password => this.setState({password}) } 
          //onChange={val => this.onChange('password', val)}
        />
        <Button title="Inscription" 
          type="submit"
          onPress={this.handleSubmit.bind(this)}
        />
      </form> 
    </View>
  );
  }
};

1 Ответ

0 голосов
/ 28 мая 2020

Вам необходимо использовать встроенную навигацию, как показано ниже:

import { NavigationActions } from 'react-navigation';
const routeName = "Home" // string e.g 'Home'
const params = {         // object (key value pair)
     key1: value1,
     key2: value2
}
NavigationActions.navigate({ routeName, params }),

or

this.props.navigation.navigate(routeName, params)

...