React Native Navigation Component Route Issue

前端 未结 4 2054
孤独总比滥情好
孤独总比滥情好 2021-02-12 13:44

New react native user here. I\'m running into an issue and I am not sure how to proceed. I was able to get react-navigation running properly and then began receiving an error: \

相关标签:
4条回答
  • 2021-02-12 13:46

    For anyone else coming here, you could be receiving the "The component for route must be a a React Component" error because you don't have a default export, which was the case for me.

    export HomeScreen extends React.Component {
     ...
    

    vs

    export default HomeScreen extends React.Component {
     ...
    

    Hope this helps someone!

    0 讨论(0)
  • 2021-02-12 13:46

    In my case putting this code block inside home.js solved the issue

     static navigationOptions = {
        navigationOptions: {
          title: "scren title",
        }
      };
    
    0 讨论(0)
  • 2021-02-12 13:58

    I think the problem is with home.js since you aren't exporting it. Try this :

    export default class Home extends Component { ... } 
    ^^^^^^^^^^^^^^
    

    Add those or just add

     export default Home; 
    

    at the end of the home.js file

    0 讨论(0)
  • 2021-02-12 14:09
    const MyNavigator = createStackNavigator({
      RouteNameOne: {
        screen: () => <HomeScreen/>
      },
      RouteNameTwo: {
        screen: () => <NewScreen/>
      }
    }, {
      initialRouteName: 'RouteNameOne'
    });
    

    It will work.

    0 讨论(0)
提交回复
热议问题