【发布时间】:2017-06-02 10:43:09
【问题描述】:
我是 react-navigation 的新手,我按照site 上的步骤操作,但是我收到一条错误消息,提示 Route 'Chat' 应该声明一个屏幕... 下面是我的代码供参考。
import React from 'react';
import {
AppRegistry,
Text,
View,
Button,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen 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>
);
}
}
AppRegistry.registerComponent('navigationApp', () => navigationApp);
这是我认为发生错误的地方
const navigationApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
class ChatScreen extends React.Component {
static navigationOptions = {
title: 'Chat with Lucy',
};
render() {
return (
<View>
<Text>Chat with Lucy</Text>
</View>
);
}
}
【问题讨论】:
-
你能测试一下在navigationApp上面声明ChatScreen吗..
-
@NeelGala 谢谢,确实有效。
标签: react-native react-navigation