我有一个react-native应用程序,带有redux和react-navigation。我正在尝试创建2个导航器。第一个是stackNavigator
,包括4个屏幕,第二个是bottomTabBarNavigator
,包括2个屏幕。两者都合并为一个
createAppContainer(createStackNavigator(navigator1, navigator2))
我也有redux。
除第二个导航器的一个屏幕外,其他所有功能都正常运行。 (它有2个屏幕,第一个屏幕工作正常,第二个屏幕抛出错误。
我已经从简单的
更改了AppNavigator连接。export default AppNavigator
到
export default connect()(AppNavigator)
App.js - main container
class App extends Component {
render() {
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<AppNavigator/>
</PersistGate>
</Provider>
);
}
}
AppNavigator.js
const navigator = createStackNavigator({
Login: {screen: LoginView, navigationOptions: {header: null}},
Menu: {screen: MenuView},
Competition: {screen: CompetitionView},
Map: {screen: CompetitionMapView},
});
const singleNavigator = createBottomTabNavigator({
CompetitionDetails: {screen: CompetitionDetailsView},
RouteView: {screen: RouteView}
});
const AppNavigator = createAppContainer(createStackNavigator({
Main: navigator,
Competition: singleNavigator
}));
singleNavigator.navigationOptions = () => {
return {
header: null,
};
};
navigator.navigationOptions = () => {
return {
header: null,
};
};
export default connect(undefined,undefined)(AppNavigator);
RouteView.js - component causing error,
// normal react component with only render and mapStateToProps / mapDispatchToProps funcs
export default connect(
mapStateToProps,
mapDispatchToProps
)(RouteView);
一切正常,直到来自“ singleNavigator”的RouteView。当我转到此屏幕时,修整结果低于错误:
不变违反:不变违反:在“ Connect(RouteView)”的上下文中找不到“存储”。将根组件包装在<Provider>
中,或者将自定义React上下文提供程序传递给<Provider>
,并将相应的React上下文使用者传递给connect选项中的Connect(RouteView)。