【问题标题】:NavigatorIOS error: undefined is not an object (evaluating routerArg.component)NavigatorIOS 错误:未定义不是对象(评估 routerArg.component)
【发布时间】:2018-09-12 09:02:47
【问题描述】:

超级,超级基础的 React Native 安装在这里;试图向我的应用程序添加一个简单的 NavigatorIOS 实例。我已经使用initialRoute 参数填充了 NavigatorIOS,并将其组件设置为另一个组件,但在运行时标题中出现错误。这是我所看到的图像。

App.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
import {Platform, StyleSheet, Text, View, NavigatorIOS, TabBarIOS} from 'react-native';
import {HomePage} from './app/pages/Home';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu'
});

type Props = {};
export default class App extends Component<Props> {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.instructions}>{instructions}</Text>
          <NavigatorIOS
              intitialRoute={{
                  component: HomePage,
                  title: 'Home'
              }}/>    
      </View>
    );
  }
}

Home.js

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

export class HomePage extends Component<{}> {

    constructor(props, context) {
        super(props, context);
    }

    _onForward = () => {
        this.props.navigator.push({
            title: 'Scene foo',
        });
    };

    render() {
        return (
          <View>
          </View>
        );
    }
}

为什么我会看到这个?在 macOS 10.14 Mojave 上运行 Xcode-10 beta 和最新版本的 React Native。

【问题讨论】:

    标签: react-native


    【解决方案1】:

    这是由于这里的错字

    <NavigatorIOS
       intitialRoute ={{ // <== here
         component: HomePage,
         title: 'Home'
    }}/> 
    

    intitialRoute 替换为initialRoute

    【讨论】:

    • 所以我的问题的原因实际上是我的近场视力不佳;好吧,现在我觉得真的很愚蠢。谢谢。
    • 别担心,我也花了一段时间才弄明白:)
    猜你喜欢
    • 2018-07-22
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多