官网:Getting started | React Navigation
安装依赖
# 之前可能已安装,这里就不需要了
npm install react-native-safe-area-context
# 使用最新版,可能会版本冲突。可以看提示需要用哪个
npm install react-native-safe-area-context@3.4.1
npm install @react-navigation/native
npm install react-native-screens
堆栈导航器
npm install @react-navigation/native-stack
选项卡导航器
npm install @react-navigation/bottom-tabs
*额外的配置
修改配置文件:android/app/src/main/java/<your package name>/MainActivity.java
添加
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}