0
我試圖讓我的第一陣營原生Android應用程序和我收到此錯誤:不確定是不是(評估「this.props.navigation.navigate」)的對象 - 陣營本地
undefined is not an object (evaluating 'this.props.navigation.navigate')
這是代碼:
import React from 'react';
import { StyleSheet, Text, View, Button, TextInput } from 'react-native';
import { StackNavigator } from 'react-navigation';
export default class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Home',
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
<Button
title="Show Centers near me"
onPress={() =>
navigate('Results', "Search Term")
}
/>
<Text>or</Text>
</View>
);
}
}
class ResultsScreen extends React.Component {
static navigationOptions = {
title: 'Results',
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
<Text>Hi</Text>
</View>
);
}
}
const App = StackNavigator({
Home: { screen: HomeScreen },
Results: { screen: ResultsScreen }
});
我不明白爲什麼錯誤即將到來。
嘗試在你的類中添加一個構造函數,像這樣:'構造函數(道具){超(道具)}' –
@HelderJulesDeBaere隱而不宣」幫助! – Akshey
顯示有關如何設置StackNavigator的更多代碼。 this.props.navigation由導航器傳遞,如果設置關閉,則可能會發生此錯誤。也嘗試搜索這個,這已被回答了很多。 – hyb175