提问者:小点点

如何在函数内部执行路由?此函数在react native中出错


功能:

  async function ridirect(APIresponse) {
const { navigate } = this.props.navigation;
if(APIresponse.success == true){
  navigate('HomeBottomBar')

}
}

这个函数正在出错。


共1个答案

匿名用户

这是因为您没有将导航道具传递给组件。可以使用导航上下文将导航传递给函数。

例如。:

import { NavigationContext } from '@react-navigation/native';

async function ridirect(APIresponse) {
  const contextType = NavigationContext;;
  if(APIresponse.success == true){
    navigate('HomeBottomBar')
  }
}