我有一个使用Redux嵌套在堆栈导航器中的制表符导航器,其结构如下:
我想要实现的是导航到主屏幕中的添加程序屏幕,Tab Nav是否有权访问Stack Nav中定义的两条路线?
虽然我看到的唯一途径是Tab Nav,但我的代码如下:
export const AppNavigator = StackNavigator({
Main: {screen: tabWithNavigator,
navigationOptions: {
title: 'Home'},
AddProgram: {
screen: AddProgramScreen,
navigationOptions: ({navigation}) => ({
title: 'Add Program'
})
},
}
});
class AppWithNavigationState extends React.Component {
render() {
const { dispatch, nav } = this.props;
return (
<AppNavigator
navigation={addNavigationHelpers({
dispatch,
state: nav,
addListener,
})}
/>
);
}
}
const mapStateToProps = state => ({
nav: state.stackNav
});
export default connect(mapStateToProps)(AppWithNavigationState);
tabWithNavigator几乎完全用TabNavigator而不是StackNavigator实现。 当我在Console Nav组件的console.log中的this.props.navigation时,只有:
"state": Object {
"key": "id-1324343445-2",
"routeName": "Main",
}
我错过了什么吗?