首页 > 解决方案 > 在Android后退按钮后重新打开应用程序时呈现导航器初始路线

问题描述

我在 ScreenA 上。当我按下 Android 后退按钮时,应用程序关闭(确定)。当我重新打开它时,我的 Root 导航器的“初始路线”被挂载(SplashScreen),它实际上运行 Bootstrap 并且发生了不好的事情。如果我在 ScreenA 上,只需按下 Android 主页按钮,然后返回,就可以了 - 我仍在 ScreenA 上,并且未呈现初始路线。知道为什么在 Android 硬件按下后会安装初始路由吗?

在我的配置下面:

export const MyRootStack = createStackNavigator<IRootStackNavigationParamList>();
function RootStackScreen() {
    return (
        <MyRootStack.Navigator
            initialRouteName={RouteNames.SplashScreen}
            headerMode={"none"}
        >
            <MyRootStack.Screen
                name={RouteNames.SplashScreen}
                component={RootSplashScreen}
            />
            <MyRootStack.Screen
                name={RouteNames.LoginScreen}
                component={LoginScreen}
                options={{ cardStyleInterpolator: forFade }}
            />
            <MyRootStack.Screen
                name={RouteNames.ScreenA}
                component={ScreenAStack}
                options={{ cardStyleInterpolator: forFade }}
            />
        </MyRootStack.Navigator>);
}

export const MyNavigationContainer: React.FC<{}> = RootStackScreen; // typing as React.FC to be able to render as JSX

任何建议都非常感谢,非常感谢!

标签: react-native-androidreact-navigationreact-navigation-v5

解决方案


推荐阅读