我正在React-Native中测试某些东西,并且 React-Navigation 库出现错误,提示: TypeError:undefined不是一个函数(评估'navigation.navigate')< / strong>。 根据react-navigation库的官方文档,我已经完成了代码:
Navigation.js
import React from 'react';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import MainScreen from './History';
import AirmineScreen from './AirmineApp';
const MainNavigator = createStackNavigator({
MainScreen: {screen:MainScreen},
HistoryScreen: {screen: HistoryScreen}
});
const Navigation = createAppContainer(MainNavigator);
export default Navigation;
Main.js
import { StackNavigator } from 'react-navigation';
...
render(){
const navigation = this.props.navigation;
return (
<TouchableOpacity onPress={() =>
navigation.navigate('HistoryScreen')}>
<Text>history</Text>
</TouchableOpacity>
)
}