我正在尝试使用反应导航。但是当我单击按钮进行导航时,什么也没有发生。我是 React Native 的新手。
应用程序.js:
function App() {
const Stack = createStackNavigator();
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
HomeScreen.js
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>HomeScreen Screen</Text>
<Button
title="Go to Detail"
onPress={() => navigation.navigate('Details')}
/>
</View>
);
}
DetailScreen.js:
function DetailsScreen() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
</View>
);
}
可能是什么问题?
编辑:我认为问题可能出在模拟器上,也许我没有正确“点击”按钮