如何在组件间本地React中导航

wtzytmuj  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(147)

我以前在react js上工作过&我是react native的新手我正在尝试在我的应用程序中的组件之间导航我正在使用reactnavigation我不知道这是最简单的方法吗
我有app.js和Dashbord.js

    • 应用程序. js**
function HomeScreen(navigation) {
  return (
    <View style={styles.prheight}>
      <View style={styles.prheight}>
        <Text style={styles.r}>Sukhprasavam</Text>
      </View>
      <View style={styles.buttonw}>
        <Button
          color="#7743DB"
          title="Lets Go"
          onPress={() => navigation.navigate('Dashbord')}
        />
      </View>
    </View>
  );
}

const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
          options={{headerShown: false}}
          name="Home"
          component={HomeScreen}
        />
        <Stack.Screen name="Dashbord" component={Dashbord} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
    • Jmeter 板**
import React from 'react';
import {StyleSheet, Text, View} from 'react-native';

export default function Dashbord() {
  return (
    <View style={styles.prheight}>
      <View style={styles.prheight}>
        <Text style={styles.r}>dada</Text>
      </View>
      <View style={styles.buttonw}>
        <Button
          color="#7743DB"
          title="Lets Go"
       
        />
      </View>
    </View>
  );
}

这一行onPress={() => navigation.navigate('Dashbord')}上的错误i am getting is undefined is not a funtion

mqkwyuun

mqkwyuun1#

HomeScreen函数稍作修改:HomeScreen(navigation)HomeScreen({ navigation })
如果要使用HomeScreen(navigation),只需更改onPress函数:onPress={() => navigation.navigate('Dashbord')}onPress={() => navigation.navigation.navigate('Dashbord')}

相关问题