【资料图】

本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。

react navigation报错怎么办?

react-navigation报错requireNativeComponent: “RNSScreenStackHeaderConfig“ was not found in the UIManage

App.tsx代码:

import React from "react";import {  SafeAreaView,  ScrollView,  StyleSheet,  Text,  View,} from "react-native";import { NavigationContainer } from "@react-navigation/native";import { createNativeStackNavigator } from "@react-navigation/native-stack"; const Stack = createNativeStackNavigator(); const HomeScreen = () => {  return (    <View>      <Text>首页</Text>    </View>  )} const MyScreen = () => {  return (    <View>      <Text>我的</Text>    </View>  )} const App = () => {  return (    <NavigationContainer>      <Stack.Navigator initialRouteName="Home">        <Stack.Screen name="Home" component={HomeScreen} />        <Stack.Screen name="Details" component={MyScreen} />      </Stack.Navigator>    </NavigationContainer>  );}; const styles = StyleSheet.create({ }); export default App;

配置:Stack.Navigator initialRouteName="Home",且配置至少2个Stack.Screen 页面。

步骤:然后重启yarn android。如果仍然报错requireNativeComponent: "RNSScreenStackHeaderConfig" was not found in the UIManager,则需要删除android\app\build\outputs\apk\debug目录下的打包的apk文件,同时删除模拟器或真机上原有的apk包。然后重新yarn android,生成打包apk,拖到到夜神模拟器,或者真机上测试。

如果仍然报错,可能需要反复上面的步骤(这边反复4次才成功)。

<Stack.Navigator initialRouteName="Home">   <Stack.Screen name="Home" component={HomeScreen} />   <Stack.Screen name="Details" component={MyScreen} /></Stack.Navigator>

推荐学习:《react视频教程》

以上就是react navigation报错怎么办的详细内容,更多请关注php中文网其它相关文章!

推荐内容