You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中Axios请求成功后无法跳转页面,请求帮助

Troubleshooting Navigation Issue After Axios Success

Hey there, let's break down why your this.props.navigation.navigate('OtpConfirm') isn't working after a successful Axios call. Here are the most likely fixes to get your navigation back on track:

1. You haven't registered the OtpConfirm screen in your StackNavigator

Looking at your provided route configuration, your AppStack only includes Home and Other screens—OtpConfirm is missing entirely. React Navigation can't navigate to a screen that isn't registered in the navigator's configuration.

Update your StackNavigator to include the OtpConfirm screen first:

// Make sure to import your OtpConfirm component first
import OtpConfirmScreen from './path/to/OtpConfirmScreen';

const AppStack = StackNavigator({
  Home: HomeScreen,
  Other: OtherScreen,
  OtpConfirm: OtpConfirmScreen // Add this line to register the screen
});

2. Verify the navigation prop is available to your component

If the component containing your _signInAsync method isn't directly rendered as a screen in the AppStack, it might not receive the navigation prop automatically.

For class components (like the one your code uses), you can use the withNavigation higher-order component from React Navigation to inject the navigation prop:

import { withNavigation } from 'react-navigation';

// Your existing component class
class AuthComponent extends React.Component {
  _signInAsync() {
    // ... your existing Axios logic here
  }

  // ... rest of your component code
}

// Wrap your component with withNavigation to get the navigation prop
export default withNavigation(AuthComponent);

3. Double-check for typos in the screen name

Ensure the string 'OtpConfirm' in your navigate call matches exactly the key you used when registering the screen in the StackNavigator—this is case-sensitive! A small typo (like 'otpconfirm' or 'Otpconfirm') will break navigation.

After applying these changes, your navigation should trigger correctly once the Axios request succeeds.

内容的提问来源于stack exchange,提问作者Anukrishnan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:20:23