React native 使用Redux thunk对React Native Redux应用程序执行异步操作后重定向到屏幕
我正在将redux(redux版本-4.0.x,react-redux版本-7.1.x)集成到现有的react本机(版本-0.60.5)应用程序中,该应用程序带有react导航(版本-4.0.x),并使用redux thunk中间件(版本-2.3.x)修改来自Axios的现有后端Http请求,以便在redux操作创建者中获取API 在fetch调用的success函数中,我无法确定如何设置react navigation以重定向到另一个屏幕。 这里我不打算使用将导航切换到redux,但需要保留react导航以管理应用程序的导航 Redux操作创建者(登录)中的获取调用示例: 然后在redux store配置中将reducer与根reducer连接,并连接到屏幕(登录屏幕),如下所示React native 使用Redux thunk对React Native Redux应用程序执行异步操作后重定向到屏幕,react-native,redux,react-navigation,redux-thunk,React Native,Redux,React Navigation,Redux Thunk,我正在将redux(redux版本-4.0.x,react-redux版本-7.1.x)集成到现有的react本机(版本-0.60.5)应用程序中,该应用程序带有react导航(版本-4.0.x),并使用redux thunk中间件(版本-2.3.x)修改来自Axios的现有后端Http请求,以便在redux操作创建者中获取API 在fetch调用的success函数中,我无法确定如何设置react navigation以重定向到另一个屏幕。 这里我不打算使用将导航切换到redux,但需要保留r
我创建了一个库来处理像这样的导航问题 它的设置和使用非常基本。您只需将导航引用设置为顶级全局级别(由库自行处理)。您只需将此代码段放入导航逻辑中,并使用主导航器设置全局级别的导航器
import NavigationService from "react-navigation-helpers";
<MainNavigator
ref={navigatorRef =>
NavigationService.setGlobalLevelNavigator(navigatorRef)
}
/>
我相信这个解决方案将解决您的困惑,并在整个项目中解决您的问题
只需将这行代码放入成功的获取结果中:
NavigationService.navigate("home")
如果您在使用react导航助手时遇到问题,请询问我任何问题
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
import NavigationService from "react-navigation-helpers";
<MainNavigator
ref={navigatorRef =>
NavigationService.setGlobalLevelNavigator(navigatorRef)
}
/>
// Goes to spesific screen from prop
NavigationService.navigate("home")
// Goes to preview screen
NavigationService.back()
NavigationService.navigate("home")