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

Android React Navigation返回键关闭应用而非返回上页面求助

Android返回键点击后应用直接关闭,无法返回上一页

问题现象

Android设备上点击返回键时,应用意外关闭,而非导航至上一页面(有演示视频展示该现象)。

测试验证

通过以下命令创建两个独立测试应用,返回键均正常工作,可正常导航至上一页面:

  • npx create-expo-app@latest
  • npx create-expo-app@latest --template react-navigation/template

已尝试的解决方案

  • 将Expo从50版本升级至51版本,并更新所有相关依赖包
  • 升级React Navigation至7版本
  • 添加import 'react-native-gesture-handler';导入语句
    以上操作均未解决问题。

当前App.tsx实现代码

import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import React from 'react';
import { Button, Text, View } from 'react-native';

const Stack = createNativeStackNavigator();

const ScreenOne = (props) => {
  return (
    <View
      style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white' }}
    >
      <Text>Screen One</Text>
      <Button
        onPress={() => {
          props.navigation.navigate('ScreenTwo');
        }}
        title="Go To Screen Two"
      />
    </View>
  );
};

const ScreenTwo = () => {
  return (
    <View
      style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white' }}
    >
      <Text>Screen Two</Text>
    </View>
  );
};

export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="ScreenOne" component={ScreenOne} />
        <Stack.Screen name="ScreenTwo" component={ScreenTwo} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

升级至Expo 51后的依赖版本

PackageVersion
@react-navigation/native^6.1.17
@react-navigation/bottom-tabs^6.5.20
@react-navigation/material-top-tabs^6.6.14
@react-navigation/native-stack^6.9.26
react-native-tab-view^3.5.2
react-native-screens4.10.5
react-native-safe-area-context4.10.5
react-native-gesture-handler~2.16.1
react-native-reanimated~3.10.1
react-native-pager-view6.3.0
react-native0.74.5
expo^51.0.0
node20.15.1
npm10.8.2

补充说明

  • 接手前任开发者搭建的导航模块,虽进行了大量修改,但基础导航功能应正常运行,实际未达预期
  • 无法在新建项目中复现该问题
  • 相关GitHub Issue:有用户反馈相同问题,表现为Android硬件返回键直接关闭应用而非执行导航回退操作

请问还能提供哪些信息以帮助定位问题原因?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:55:56