React Native Navigator 引入的那些坑

来源:互联网 发布:日本军国主义知乎 编辑:程序博客网 时间:2024/05/23 01:05

讲诉一下进入Navigator的那些错误。

当要引入Navigator的使用通常的做法是:

import {Navigator} from "react-native"

当我们进行执行react native 程序的时候 告知我们 该组件已经不存在 :

'Navigator is deprecated and has been removed from this package. It can now be installed ' +      'and imported from `react-native-deprecated-custom-components` instead of `react-native`. ' +      'Learn about alternative navigation solutions at http://facebook.github.io/react-native/docs/navigation.html'   

此时我们将要做的便是通过引用:

react-native-deprecated-custom-components 来导入 Navigator 组件


步骤如下:

1、打开程序的根目录(也就是和 Package.json 同级的目录)

2、使用cmd 命令工具 或者 Git Bash Here (前提是安装过GIT工具)  

      输入命令:    npm  install   react-native-deprecated-custom-components  --save 

(下载并保存,此时package.json 文件 中 便会增加一条对该库的引用代表成功)

3、在使用Navigator的地方引用便可使用。

引用方式:import {Navigator} from "react-native-deprecated-custom-components" 

注意:在引用时 一定在导入 Navigator的时候加上 {}  要不然会报错。

同时:当我在使用  npm  install   react-native-deprecated-custom-components  --save  时报错


解决方法:

使用命令: npm  i   react-native-deprecated-custom-components  --save 

如果此方法还不能解决。

解决方法:

使用yarn命令(前提是自己有yarn的配置环境)

使用命令:yarn add  react-native-deprecated-custom-components  --save 


最终解决Navigator的下载。