无法通过导航导航到另一个屏幕。导航

时间:2020-04-19 18:47:32

标签: reactjs react-native react-redux

我有一个具有功能的登录类:

  async _logInWithFacebook() {
    await Facebook.initializeAsync(fbConfig.APP_ID);
    const { type, token } = await Facebook.logInWithReadPermissionsAsync(
      fbConfig.APP_ID,
      {
        permissions: ["public-profile", "email"],
      }
    );
    if (type === "success") {
      this.props.login(token, "facebook");
      this.props.navigation.navigate("Home");
    } else {
      throw new Error("Something wrong with facebook auth");
    }
  }

按下按钮登录时会调用它。我还有一个HomeScreen类,按下按钮后我想在其中移动。

class HomeScreen extends Component {
  componentDidMount() {
    this.props.fetchMyMeetups();
  }
  render() {
    const {
      myMeetups: { isFetched, data, error },
    } = this.props;
    return (
      <View style={styles.root}>
        <View style={styles.header}>
          <View style={styles.add}>
            <CreateMeetupScreen />
          </View>
        </View>
        <View style={styles.topContainer}>
          <Text>HomeScreen</Text>
        </View>
        <View style={styles.bottomContainer}>
          <MyMeetupsList meetups={data} />
        </View>
      </View>
    );
  }
}
export default HomeScreen;

还有我的导航器:

export function Navigator() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Login">
        <Stack.Screen name="Login" component={LoginScreen} />
        <Stack.Screen name="Home" component={HomeScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );

所以当我按下按钮时,我得到一个错误:[未处理的承诺拒绝:TypeError:未定义不是对象(正在评估'_ref.navigation')]

1 个答案:

答案 0 :(得分:0)

首先,控制台将您的道具记录在每个组件中,并检查是否在其上进行导航,然后不要忘记传递您要传递给下一个屏幕的道具作为导航功能的第二项,如

this.props.navigation.navigate("Home",{SOME PROPS HERE});

然后您将可以在下一页中使用它并使用它。 我希望它对<3

有帮助