返回响应错误500 React Native

时间:2017-06-06 07:30:52

标签: android react-native

我正在使用react-native框架来开发我的小型Android应用程序。我试图从index.android.js重定向到Home.js.当我运行它时,它显示我的红色错误消息模拟器

index.android.js

import React, { Component } from 'react';
import {AppRegistry,Text,View} from 'react-native';
import Home from 'App/Component/Home';

export default class mylApp extends Component {
  render() {
    return (
      <View>
         <Home />
      </View>
    );
  }
}

AppRegistry.registerComponent('reactTutorialApp', () => reactTutorialApp);

Home.js

import React, { Component } from 'react';
import {Text,View} from 'react-native';


class Home extends Component {
   state = {
      myTxt: 'hiiiiiiiiiiiiiiiiiiiiiii';
   }

   render() {
      return (
         <View>
            <Text>
               {this.state.myTxt}
            </Text>
         </View>
      );
   }
}

export default Home;

enter image description here

1 个答案:

答案 0 :(得分:1)

使用此导入路径import Home from 'App/Component/Home';进行检查。我假设Home.js在Project(文件夹)中 - &gt; App(文件夹) - &gt;组件(文件夹) - &gt; Home.js.如果是这样,那么您需要像import Home from './App/Component/Home';

那样导入

更新1:

<强> index.android.js

import React, { Component } from 'react';
import {AppRegistry,Text,View} from 'react-native';
import Home from './App/Component/Home';

export default class mylApp extends Component {
  render() {
    return (
      <View>
         <Home />
      </View>
    );
  }
}

AppRegistry.registerComponent('reactTutorialApp', () => mylApp);

更新2

<强> Home.js

import React, { Component } from 'react';
import {Text,View} from 'react-native';


class Home extends Component {
   state = {
      myTxt: 'hiiiiiiiiiiiiiiiiiiiiiii'
   }

   render() {
      return (
         <View>
            <Text>
               {this.state.myTxt}
            </Text>
         </View>
      );
   }
}

export default Home;