React-Native - 找不到变量:title

时间:2016-09-15 22:38:50

标签: react-native

新的React-Native安装。我正在尝试设置它。在index.ios.js中,我有:

class thingy extends Component {
  render() {
    return (
      <NavigatorIOS
        style={styles.container}
        initialRoute={(
          title: 'Thingy',
          component: Main
        )} />
    );
  }
}

当我运行时,应用程序会给我错误:

找不到变量:title

我不确定为什么它会给我这个错误。有什么想法吗?

主要组成部分:

var React = require('react-native');

var {
  View,
  Text,
  StyleSheet
} = React;

var styles = StyleSheet.create({
  mainContainer: {
    flex: 1,
    padding: 30,
    marginTop: 65,
    flexDirection: 'column',
    justifyContent: 'center',
    backgroundColor: '#48BBEC'
  },
  title: {
    marginBottom: 20,
    fontSize: 25,
    textAlign: 'center',
    color: '#fff'
  },
  searchInput: {
    height: 50,
    padding: 4,
    marginRight: 5,
    fontSize: 23,
    bordderWidth: 1,
    borderColor: 'white',
    borderRadius: 8,
    color: 'white'
  },
  buttonText: {
    fontSize: 18,
    color: '#111',
    alignSelf: 'center'
  },
  button: {
    height: 45,
    flexDirection: 'row',
    backgroundColor: 'white',
    borderColor: 'white',
    borderWidth: 1,
    bordeRadius: 8,
    marginBottom: 10,
    marginTop: 10,
    alignSelf: 'stretch',
    justifyContent: 'center'
  },
});

class Main extends React.Component{
  render(){
    return (
      <View style={styles.mainContainer}>
        <Text> Testing the Router </Text>
      </View>
    )
  }
};

module.exports = Main;

1 个答案:

答案 0 :(得分:1)

啊,看起来initialRoute应该是一个对象,但是你用括号括起来了:

现在如何:

initialRoute={(
  title: 'Thingy',
  component: Main
)}

实际应该是:

initialRoute={{
  title: 'Thingy',
  component: Main
}}