2017-06-27 21 views
0

我很新的学习反应,并根据这个实例简单: 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' }) } />); } 
} 

但是当我运行此我得到那个说

错误

“没有定义ProfileScreen”

我看不到在这里做什么,因为这不是文件页面我联系上。

回答

1

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

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> 
); 
+0

Thanks..I刚刚添加that..now错误是“路线‘家’应申报的屏幕”。这看起来很奇怪,因为它出现在上面的const App行中。 – Allen

+0

你只需要把应用程序组件放在其他两个之后。 –

+0

试试这个: https://snack.expo.io/SJCtk_1Vb –