目前,我对屏幕有这种污点:

const Tabs = TabNavigator({
  Home: {
    screen: Home,
    navigationOptions: {
      tabBarLabel: 'Home',
      tabBarIcon: <Image style={{height: 22, width: 22}} source={require('../assets/images/nav-home.png')}/>,
      header: null
    }
  },
  Thanks: {
    screen: Thanks,
    navigationOptions: {
      tabBarLabel: 'Thanks',
      tabBarIcon: <Image style={{height: 22, width: 21}} source={require('../assets/images/nav-thanks.png')}/>,
      header: null
    }
  },
  Profile: {
    screen: Profile,
    navigationOptions: {
    gesturesEnabled: false
    }
  },
},
{
  initialRouteName: 'Home',
  tabBarPosition: 'bottom',

},
)

const Drawer = DrawerNavigator(
  {
    Tabs: {
      screen: Tabs,
      navigationOptions: {
        drawerLabel: () => null
      }
    },
    Search: {screen: SearchAndProfile}
  },
  {
    drawerPosition: 'right',
    initialRouteName: 'Tabs',
    drawerOpenRoute: 'DrawerOpen',
    drawerCloseRoute: 'DrawerClose',
    drawerToggleRoute: 'DrawerToggle'
})

const NotLoggedIn = StackNavigator(
  {
   LoginScreen: {
screen: Login,
     navigationOptions: {
          gesturesEnabled: false,
      }
    },
   Drawer: {screen: Drawer}
  },
  {
   initialRouteName: 'LoginScreen',
   headerMode: 'none',
   navigationOptions: {
    gesturesEnabled: false,
  }
  }
)

const LoggedIn = StackNavigator(
  {
   Drawer: {screen: Drawer}
  },
  {
   headerMode: 'none',
   navigationOptions: {
    gesturesEnabled: false,
  },
  transitionConfig : () => ({
    transitionSpec: {
      duration: 0,
      timing: Animated.timing,
      easing: Easing.step0,
    },
  }),
  }
)

export const Root = StackNavigator(
  {
    Splash:{screen: Splash},
    LoggedIn: {
      screen: LoggedIn,
      navigationOptions: {
        gesturesEnabled: false
      }
    },
    NotLoggedIn: {screen: NotLoggedIn}
  },
  {
    headerMode: 'none',
    navigationOptions: {
    gesturesEnabled: false,
  },
  transitionConfig : () => ({
    transitionSpec: {
      duration: 0,
      timing: Animated.timing,
      easing: Easing.step0,
    },
  }),
  }
)


并且我试图将参数从启动屏幕传递到登录屏幕,但似乎在TabNavigator中未定义参数(在主屏幕中)

我像这样通过

this.props.navigation.navigate('LoggedIn',{testData: 'testing'})


在我登录this.props.navigation.state.params时在componentDidMount()函数中获得未定义。可能是什么原因?

最佳答案

你有尝试过吗
(来自此discussion on github

this.props.navigation.navigate('LoggedIn', {}, {
    type: "Navigate",
    routeName: "Drawer",
    params: {testData: 'testing'},
})

09-27 07:25