2017-06-27 19 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 –