开发者问题收集

react-navigation v5(下一步):从不同父级的子屏幕导航到嵌套的子屏幕

2019-12-11
2556

使用 react-navigation v5(下一步):

高级问题:从不同父级的子屏幕导航到嵌套的子屏幕。

这是我的根导航器

export const AppNavigator = (props): React.ReactElement => (
   <Stack.Navigator {...props} headerMode='none' mode={'modal'}>
      <Stack.Screen name={AppRoute.AUTH} component={AuthNavigator} />
      <Stack.Screen name={AppRoute.HOME} component={HomeNavigator} />
   </Stack.Navigator>
);

这是我的 AuthNavigator:

export const AuthNavigator = (): React.ReactElement => (
   <Stack.Navigator headerMode='none'>
      <Stack.Screen name={AppRoute.SIGN_IN} component={SignInScreen} />
      <Stack.Screen name={AppRoute.LOG_OUT} component={LogOutScreen} />
      <Stack.Screen name={AppRoute.SIGN_UP} component={SignUpScreen} />
      <Stack.Screen
         name={AppRoute.RESET_PASSWORD}
         component={ResetPasswordScreen}
      />
   </Stack.Navigator>
);

HomeNavigator 中的页面内,我想直接导航到 LogOutScreen / AppRoute.LOG_OUT

我可以调用 navigate(AppRoute.AUTH) ,但如果我调用 navigate(AppRoute.LOG_OUT) ,则没有任何效果。

1个回答

类似这样的代码应该可以工作:

// Navigate to 'AppRoute.LOG_OUT' inside 'AppRoute.AUTH'
navigation.navigate(AppRoute.AUTH, { screen: AppRoute.LOG_OUT });

https://reactnavigation.org/docs/en/next/nesting-navigators.html#navigating-to-a-screen-in-a-nested-navigator

satya164
2019-12-11