反应导航 - 遵循文档但收到错误

时间:2017-06-27 03:25:18

标签: reactjs react-native

我对学习反应非常新,并且只是遵循这个例子: https://facebook.github.io/react-native/docs/navigation.html

import { StackNavigator, } from 'react-navigation';
const App = StackNavigator(
 { Home: { screen: HomeScreen }, Profile: { screen: ProfileScreen }, });


class HomeScreen extends React.Component { 
   static navigationOptions = { title: 'Welcome', }; 
    render() { 
         const { navigate } = this.props.navigation; 
        return ( <Button title="Go to Jane's profile" onPress={() => navigate('Profile', { name: 'Jane' }) } /> ); } 
}

但是当我运行这个时,我得到一个错误,上面写着

  

&#34;未定义ProfileScreen&#34;

我无法看到这里要做什么,因为这不在我链接的文件页面上。

1 个答案:

答案 0 :(得分:1)

您只是缺少一个名为ProfileScreen的React组件。你有一个HomeScreen:

    class HomeScreen extends React.Component { 
       static navigationOptions = { title: 'Welcome', }; 
        render() { 
            const { navigate } = this.props.navigation; 
            return ( 
                <Button 
                    title="Go to Jane's profile" 
                    onPress={() => navigate('Profile', { name: 'Jane' }) } 
                /> 
            ); 
        } 
     }

现在只需定义某种ProfileScreen:

const ProfileScreen = () => (
    <View>
        <Text>ProfileScreen</Text>
    </View>
);