我正在本地运行下面的示例,但遇到TypeError。
import HomeScreen from './screens/HomeScreen';
import SecoundScreen from './screens/SecoundScreen';
import ThirdScreen from './screens/ThirdScreen';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Second" component={SecoundScreen} />
<Stack.Screen name="Third" component={ThirdScreen} />
</Stack.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyStack />
</NavigationContainer>
);
}
我复制了示例中的,并且在我修改它之前都无效[@ C0]
https://reactnavigation.org/docs/en/stack-navigator.html
下面的代码有效!我刚刚安装了react-navigation,所以我应该拥有最新版本!
https://snack.expo.io/?platform=android&name=createStackNavigator%20%C2%B7%20React%20Navigation&dependencies=%40react-native-community%2Fmasked-view%40%5E0.1.1%2C%40react-navigation%2Fnative%40%5E5.0.0%2C%40react-navigation%2Fbottom-tabs%40%5E5.0.0%2C%40react-navigation%2Fdrawer%40%5E5.0.0%2C%40react-navigation%2Fmaterial-bottom-tabs%40%5E5.0.0%2C%40react-navigation%2Fmaterial-top-tabs%40%5E5.0.0%2C%40react-navigation%2Fnative-stack%40%5E5.0.0%2C%40react-navigation%2Fstack%40%5E5.0.0%2Creact-native-gesture-handler%401.5.2%2Creact-native-reanimated%401.4.0%2Creact-native-safe-area-context%400.6.0%2Creact-native-screens%402.0.0-alpha.12&sourceUrl=https%3A%2F%2Freactnavigation.org%2Fexamples%2F5.x%2Fsimple-stack.js
知道第一个版本为什么会失败吗?