我正在使用react导航库,特别是${server_2_details}
https://reactnavigation.org/docs/en/params.html上的文档介绍了如何使用堆栈导航器在路由之间传递参数,而Im使用标签导航器,我找不到跳出来的任何东西来解释如何在标签导航设置中进行操作>
我在App.js中的标签导航器是
createBottomTabNavigator
watchList路由包含一个名为symbol的json文件,我希望将其传递到alertScreen.js中的警报路由
const BottomTabMenu = createBottomTabNavigator (
{
WatchList: { screen: WatchListScreen },
Alerts: { screen: AlertsScreen },
Analytics: { screen: AnalyticsScreen },
Settings: { screen: SettingsScreen },
},
{
initialRouteName: 'WatchList',
defaultNavigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
let IconComponent = Ionicons;
let iconName;
if (routeName === 'WatchList') { iconName = 'md-list'; }
if (routeName === 'Alerts') { iconName = 'md-alert'; }
if (routeName === 'Analytics') { iconName = 'md-analytics'; }
if (routeName === 'Settings') { iconName = 'md-settings'; }
return <IconComponent name={iconName} size={25} color={tintColor} />;
},
}),
tabBarOptions: {
activeTintColor: 'tomato',
inactiveTintColor: 'gray',
},
}
);
const AppContainer = createAppContainer(BottomTabMenu);
ALERTSSCREEN.JS
export default class WatchListScreen extends React.Component {
constructor(props) {
super(props)
this.state = {
symbols: [],
}
}
LOTS OF OTHER STUFF
根据文档,我需要传递数据的行将是这样的
export default class AlertsScreen extends React.Component {
render() {
//according to the docs, this is how to receive in the props
const { navigation } = this.props;
const jsonWatchList = navigation.getParam('jsonWatchList', '[]');
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>blah blah blah</Text>
</View>
);
}
}
唯一的问题是我不知道应该去哪里。
答案 0 :(得分:1)
在您的链接(https://reactnavigation.org/docs/en/params.html)中有详细记录。
它说明了路线之间如何传递参数。使用stackNavigator
还是createBottomTabNavigator
按您希望的方式传递参数:
this.props.navigation.navigate('jsonWatchList', {
jsonWatchList: [lots of data here],
});
在另一个屏幕上,像这样获得它们:
const data = this.props.navigation.getParam('jsonWatchList');