React Native 使用不同的 props 导航到同一页面

Sen*_*dru 2 react-native react-native-android react-navigation react-navigation-drawer

我正在开发一个使用侧抽屉的 RN 应用程序。(RN 版本:0.59.8)

const DrawerNavigator = createDrawerNavigator(
    {
        Home: {
            screen: HomeScreen
        },
        Poems: {
            screen: PoemsScreen
        },
        Contest: {
            screen: ContestScreen
        },
        AboutMe: {
            screen: AboutMeScreen
        }
    },
    DrawerConfig
);

export default createAppContainer(DrawerNavigator);
Run Code Online (Sandbox Code Playgroud)

使用的 react-navigation 版本是 3.11.0。在菜单中,多个子项指向同一个页面,即 ViewPager,但具有不同的参数(页面索引)。问题是以下方法都不起作用:

  1. 尝试使用推送而不是导航(返回_this2.props.navigation.push is not a function
  2. 试图重置相应的堆栈。
const resetAction = StackActions.reset({
   index: 0,
   key: 'Poems',
   actions: [NavigationActions.navigate({ routeName: 'Poems' })]
})
this.props.navigation.dispatch(resetAction)
Run Code Online (Sandbox Code Playgroud)

(也试过key: null

任何帮助深表感谢!

Har*_*eno 11

尝试阅读https://reactnavigation.org/docs/en/navigating.html#navigate-to-a-route-multiple-times

您需要使用 navigation.push() 来运行具有不同参数的组件副本。