React Native 导航react-navigation 报错找不到的问题,或者安装依赖后react-native-gesture-handler依赖库时报错的问题
解决办法:如果已经安装react-navigation
可以先 npm uninstall react-navigation;
然后查看react native 版本。在package.json 文件中如下。 "react-native": "0.56.0",即是版本号 修改到0.56.0 然后重新运行npm install
"dependencies": {
"jetifier": "^1.6.5",
"prop-types": "latest",
"react": "16.9.0",
"react-native": "0.56.0",
"uuid": "latest"
},
运行完成依次如下操作
yarn add react-navigation
yarn add react-native-gesture-handler
yarn add react-navigation-stack
npm install --save react-navigation-tabs
然后 部分辅助包 按编译提示install
react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false 。生成配置文件 需要手动创建 assets目录
应用
import {createBottomTabNavigator} from 'react-navigation-tabs';
import {createStackNavigator} from 'react-navigation-stack'
import {createAppContainer} from 'react-navigation';
const navigations=createStackNavigator({
App:{
screen:App
},
RNCameraDemo:{
screen:RNCameraDemo
}
})
const AppContainer = createAppContainer(navigations);
AppRegistry.registerComponent(appName, () => AppContainer);
跳转
this.navigate('demo')
navigate=(link)=>{ const {navigate} =this.props.navigation; navigate(link) }