react navigation報(bào)錯的解決辦法:1、配置“Stack.Navigator initialRouteName="Home"”,然后重啟“yarn android”;2、刪除“androidappbuildoutputsapkdebug”目錄下的打包的apk文件,同時刪除模擬器或真機(jī)上原有的apk包,然后重新執(zhí)行“yarn android”即可。
本教程操作環(huán)境:Windows10系統(tǒng)、react18.0.0版、Dell G3電腦。
react navigation報(bào)錯怎么辦?
react-navigation報(bào)錯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。如果仍然報(bào)錯requireNativeComponent: "RNSScreenStackHeaderConfig" was not found in the UIManager,則需要刪除androidappbuildoutputsapkdebug目錄下的打包的apk文件,同時刪除模擬器或真機(jī)上原有的apk包。然后重新yarn android,生成打包apk,拖到到夜神模擬器,或者真機(jī)上測試。
如果仍然報(bào)錯,可能需要反復(fù)上面的步驟(這邊反復(fù)4次才成功)。
<Stack.Navigator initialRouteName="Home"> <Stack.Screen name="Home" component={HomeScreen} /> <Stack.Screen name="Details" component={MyScreen} /> </Stack.Navigator>
推薦學(xué)習(xí):《react視頻教程》