0
當我的App.js中顯示undefined不是一個對象(評估'this.props.navigation.navigate')時,我遇到了一些問題。當它在主屏幕和chatsrceen之間切換時,我一直在反應本機文檔。我仍然無法使它工作。有人能幫助我嗎?使用StackNavigator在屏幕之間導航
import React, { Component } from 'react';
import {
StyleSheet,
Text,
Button,
View,
Navigator,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
class App extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<View>
<Text>Hello, Chat App!</Text>
<Button
onPress={() => navigate('Chat')}
title="Chat with Lucy"
/>
</View>
);
}
}
class ChatScreen extends React.Component {
static navigationOptions = {
title: 'Chat with Lucy',
};
render() {
return (
<View>
<Text>Chat with Lucy</Text>
</View>
);
}
}
const App1 = StackNavigator({
Home: { screen: App },
Chat: { screen: ChatScreen },
});
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
export default App1
哪裏是你的'AppRegistry.registerComponent(...)'? – QoP