我正在使用CRNA v0.44。我正在进行两屏注册。我在第一个屏幕上,现在我想使用反应导航转到第二个屏幕。

但是出现错误:


  未定义不是对象(评估“ this.props.navigation.navigate”)


我已经浏览了互联网,发现需要将prop传递给按钮,但无法弄清楚怎么做?

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' })
        }
      />
  )
  }
}

最佳答案

我认为您在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);

10-05 20:41