【问题标题】:undefined is not an object (evaluating 'this.props.navigation.navigate') (common ques) (CRNA)undefined 不是对象(评估“this.props.navigation.navigate”)(常见问题)(CRNA)
【发布时间】:2017-06-15 17:17:28
【问题描述】:

我正在使用 CRNA v0.44 。我正在做一个两屏注册。我在第一个屏幕上,现在我想使用 react-navigation 转到第二个屏幕。

但出现错误:

undefined 不是对象(评估 'this.props.navigation.navigate')

我浏览了互联网,发现需要将道具传递给按钮但无法弄清楚如何?

SignupForm.js:

 import {
  StackNavigator,
} from 'react-navigation'
import SignupForm2 from './SignupForm2'
const App = StackNavigator({
  SignupForm2: { screen: SignupForm2 },
});
export default class SignupForm extends Component {

render () {
 const { navigate } = this.props.navigation
return (
 <Button
        title="Go to Jane's profile"
        onPress={() =>
          navigate('SignupForm2', { name: 'SignupForm2' })
        }
      />
  )
  }
}

【问题讨论】:

  • 您是否将导航道具传递给任何地方的组件?

标签: javascript react-native react-native-android react-navigation create-react-native-app


【解决方案1】:

我认为您在 AppRegistry.registerComponent 中呈现 SignupForm,请尝试以下代码。您还需要在 StackNavigator 中包含 SignupForm 并在 AppRegistry.registerComponent 中呈现变量 App。

import {
 StackNavigator,
} from 'react-navigation'

import SignupForm2 from './SignupForm2'

const App = StackNavigator({
  SignupForm: { screen: SignupForm }
  SignupForm2: { screen: SignupForm2 },
});

export default class SignupForm extends Component {

render () {
const { navigate } = this.props.navigation
  return (
    <Button
      title="Go to Jane's profile"
      onPress={() =>
       navigate('SignupForm2', { name: 'SignupForm2' })
      }
    />
  )
 }
}

AppRegistry.registerComponent('yourApp', () => App);

【讨论】:

    【解决方案2】:

    我猜第一个SignupForm 也必须是导航器的一部分,然后告诉导航器初始屏幕是SignupForm

    【讨论】:

    • 也试过了...你能通过远程访问检查吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 2020-07-16
    相关资源
    最近更新 更多