javascript - How to redirect in React Navigation after login - Stack Overflow

StackNavigator is my configuration. How do to redirect to another screen after user pressed login and s

StackNavigator is my configuration.

How do to redirect to another screen after user pressed login and successfully obtained a token. Below are the current screen.

const MainScreenNavigator = StackNavigator({
  Login: { screen: LoginScreen },
  Protected: { screen: ProtectedScreen },
});

StackNavigator is my configuration.

How do to redirect to another screen after user pressed login and successfully obtained a token. Below are the current screen.

const MainScreenNavigator = StackNavigator({
  Login: { screen: LoginScreen },
  Protected: { screen: ProtectedScreen },
});
Share Improve this question edited Jul 16, 2017 at 15:39 Sydney 1,4391 gold badge16 silver badges22 bronze badges asked Jun 16, 2017 at 20:40 JoseJose 331 gold badge1 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

use navigate('Protected')

and if you want to pass params navigate('protected',{user:'John'})

and retrive it as props this.props.Navigation.state.params.user

class LoginScreen extends React.Component {
  static navigationOptions = {
    title : 'Login'
  };

  login() {
    const { navigate } = this.props.navigation;
    navigate('Protected', { user: 'John' })
  };

  render() {
    return (
      <View>
        <Button
          onPress={() => this.login()}
          title="Login"
        />
      </View>
    )
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744787949a4593741.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信