抽屉导航器的contentComponent内部的stackNavigator

时间:2019-04-25 04:22:20

标签: react-native react-navigation

我正在使用抽屉式导航器构建一个应用程序。应该有由contentComponent制作的自定义侧面菜单屏幕,但是问题是当用户按下按钮时,我需要在抽屉内进行导航。我试图将stackNavigator传递给customComponent,这使我返回“没有为键定义路由...”。

请,您能帮我在不关闭抽屉的情况下在抽屉中进行导航吗?

const tempSN = createStackNavigator(
  {
    screen: DrawerScreen,
    screen2: ProfileSetupScreen
  },
  { initialRouteName: "screen" }
);

const DrawerStack = createDrawerNavigator(
  {
    MainStack: MainStack
  },
  {
    contentComponent: tempSN, // If I pass here DrawerScreen directly, it works
    navigationOptions: {
      header: null
    }
  }
);

1 个答案:

答案 0 :(得分:1)

您可以尝试以下吗?

const DrawerStack = createDrawerNavigator(
  {
    MainStack: MainStack
  },
  {
    contentComponent: drawerComponent,//Your drawer component.Not stack navigator.
    navigationOptions: {
      header: null
    }
  }
);

const drawerStack = createStackNavigator(
  {
    drawerNav: DrawerStack,// Here is the drawer included.
    screen: DrawerScreen,
    screen2: ProfileSetupScreen
  },
);

将抽屉导航添加到堆栈导航中。而且,当您要导航到屏幕“ screen2”时,请像this.props.navigation.navigate("screen2")