4

嗨,我是新的反應原生,我面臨與路由奇怪的問題。我做錯了什麼,但需要有人來指導我。路由應該聲明一個屏幕。 [反應原生導航錯誤]

index.android.js

import { LandingScreen } from './src/components/landing_screen.js' 
import HomeScreen from './src/app_component.js' 
import { StackNavigator } from 'react-navigation'; 

const SimpleApp = StackNavigator({ 
    Home: { screen: HomeScreen }, 
    Landing: { screen: LandingScreen}, 
}); 

AppRegistry.registerComponent('HomeScreen',() => SimpleApp); 

app_component.js

// Other imports ... 
export default class HomeScreen extends Component { 
    static navigationOptions = { 
    title: 'Home Screen', 
    }; 
    render() { 
    const { navigate } = this.props.navigation; 
    return (
     <View style={styles.container}> 
     <Text style={styles.welcome}> 
      Welcome to React Native! 
     </Text> 
     <Text style={styles.instructions}> Hello CHannoo!!!</Text> 
     <Text style={styles.instructions}> 
      To get started, edit index.android.js 
     </Text> 
     <Text style={styles.instructions}> 
      Double tap R on your keyboard to reload,{'\n'} 
      Shake or press menu button for dev menu 
     </Text> 
     <Button 
      title="Go to 2nd Page" 
      onPress={() => 
      // alert('hello'); 
      navigate('LandingScreen') 
      // navigate('Home', { name: 'Jane' }) 
      } 
     /> 
     </View> 
    ); 
    } 

    componentDidMount() { 
    SplashScreen.close({ 
     animationType: SplashScreen.animationType.scale, 
     duration: 850, 
     delay: 500, 
    }) 
    } 
} 

landing_screen.js

export default class LandingScreen extends Component { 
static navigationOptions = { 
    title: 'Landing Screen Title', 
}; 
render() { 
    return (........) 
} 

它如果我們刪除路線登陸工作正常。但是當我們添加這條路線時,我們會得到錯誤

Route'Landing'應該聲明一個屏幕。例如......

回答

3

您的LandingScreen已導出爲default,但您是按名稱導入的。

你的import語句是這樣的:

import { LandingScreen } from './src/components/landing_screen.js' 

低於線(沒有大括號)替換它:

import LandingScreen from './src/components/landing_screen.js' 

應該解決的問題。

但你可能會得到一個新的錯誤作爲@Medet指出,因爲你必須要改變這一行:

navigate('LandingScreen') 

到:

navigate('Landing') 

因爲你的網名登陸。

+0

感謝黃昏奏效。 問題在於import語句。導航工作正常,因爲我在這裏拼寫錯了:) –

1

你叫navigate('LandingScreen')
但網名是Landing
+ @黃昏的答案應該解決