2

反应本机 Wix Navigation.push 可能未处理的承诺拒绝:错误:无法执行堆栈命令

登录.js

signUpLink =(screenName) => {


          Navigation.push(this.props.componentId, {
  component: {
    name: screenName,
  }
});


    }

 <TouchableOpacity style={styles.buttonText}   onPress={this.signUpLink('videostreme.SignUpScreen')}>
                <Text style={styles.signUpText} >First time here?? Sign Up</Text>
                </TouchableOpacity>

index.js

Navigation.registerComponent('videostreme.LoginScreen', () => Login);
Navigation.registerComponent('videostreme.MainScreen', () => Main);
Navigation.registerComponent('videostreme.SignUpScreen', () => SignUp);
Navigation.registerComponent('videostreme.SplashScreen', () => Splash);

Navigation.events().registerAppLaunchedListener(() => {
  Navigation.setRoot({
    root: {
     stack: {
         children: [
         {
             component: {
                 name: 'videostreme.MainScreen'
             }
         },

         ]
     }
    }
  })
})

如何处理这个承诺(Navigation.push),有人知道这个吗?

4

1 回答 1

2

当我直接给出componentId而不是this.props.componentId时它正在工作(当我控制台时这是未定义的)。所以我直接给componentId,

redirectPageHandler = screenName => {
  Navigation.push('login', {
   component: {
      name: screenName
   }
  });
}

this.props.componentId未定义的原因是,我们需要从父组件传递道具。

我的子组件是Login,父组件是App

应用程序.js

render() {
  return (
   <Login {...this.props} />
  )
}

现在,我们可以在子组件中使用this.props.componentId

登录.js

redirectPageHandler = screenName => {
  Navigation.push(this.props.componentId, {
   component: {
      name: screenName
   }
  });
}
于 2019-04-10T08:56:58.577 回答