this.props.navigation未定义(createStackNavigator)

时间:2019-12-09 09:33:39

标签: javascript reactjs react-native

我想在ReactNative上创建一个简单的导航示例。

这是下面的代码;


FIELD:    nodeName <string>

DESCRIPTION:
     NodeName is a request to schedule this pod onto a specific node. If it is
     non-empty, the scheduler simply schedules this pod onto that node, assuming
     that it fits resource requirements.

当我这样编写代码时,由于未定义Line12 oc patch dc nginx-example -p '{"spec":{"template":{"spec":{"nodeName": "ip-10-0-169-74.us-east-2.compute.internal"}}}}',所以会发生错误。

有人可以解决吗?

2 个答案:

答案 0 :(得分:1)

请尝试以下代码:

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

      createAppContainer
    } from 'react-navigation';
    import { createStackNavigator } from 'react-navigation-stack';

class Home extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home</Text>
        <Button
          title="To the detail Page"
          onPress={() => this.props.navigation.navigate('DetailScreen')}
        />
      </View>
    );
  }
}

class Detail extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Detail Page</Text>
      </View>
    );
  }
}

const APpStack =  createStackNavigator({
  HomeScreen: { screen: Home },
  DetailScreen: { screen: Detail },
})

const App = createAppContainer(APpStack);

export default App;

您还可以检查有效的解决方案link expo

希望有帮助。毫无疑问

答案 1 :(得分:0)

您需要一个构造函数来定义用于存储导航数据(以及其他)的属性:

class Home extends React.Component {
  constructor(props) {
    super(props);
    // ...
  }