【问题标题】:Stack navigater not working react native堆栈导航器不起作用反应原生
【发布时间】:2020-02-27 14:28:54
【问题描述】:

使用stacknaviger时,报错

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

1-import { createStackNavigator } from 'react-navigation';
添加 onPress 事件时显示错误

【问题讨论】:

    标签: reactjs


    【解决方案1】:

    您无需导入任何内容。 Jist 通过 createStackNavigator 定义路由。

    export default createStackNavigator({
      Home: {
        screen: Home
      },
    });
    

    React Navigation 通过 props 提供 API。 您需要使用道具进行过渡。

    使用导航道具。 this.props.navigation.navigate("首页") 就是例子。

    render() {
      const { navigate } = this.props.navigation
      return (
        <Button title="press" onPress ={() => navigate("Home")}/>
    

    我建议通过 consolr.log(this.props) 确认您的道具

    通过 stackNavigator 定义您的路线。

    阅读此“在屏幕之间移动” https://reactnavigation.org/docs/en/navigating.html

    【讨论】:

    • 它显示同样的错误 undefined is not an obhect(evaluating 'this.props.navigation.navigate')
    • 1.我想你忘了导出默认值。 2. React Navigation 不要在子组件中使用 this.props.navigation。在 ChildButton onPress={() => this.props.navigation(this.props.route )}
    • 实际上我正在创建一个小应用程序,其中首先出现一个启动屏幕,然后一个活动带有一个开始按钮,因此想要添加导航以转到其他屏幕到此开始按钮
    • 然后检查 stackNavigator。 undefined is not an object(evaluation'_this2.props.navigation.navigate') 表示 props.navigation 是 undefiend。所以你需要将 porps 传递给你的组件。 const AccountSubNav = StackNavigator( { LandingScreen: {screen: LandingScreen}, }) 是示例
    猜你喜欢
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多