首页 > 解决方案 > 转到子场景选项卡 - react-native-router-flux

问题描述

这是我的路由器层次结构:

<Tabs
  key='tabbar'
  backToInitial
  onTabOnPress={() => {
    console.log('Back to initial and also print this');
  }}
  swipeEnabled
  hideNavBar={true}
>
  <Scene
    title='Profilo'
    key='profile'
    component={Profile}
    tabBarLabel='Profilo'
    icon={TabBarIcon}
    name='ios-person'
    titleStyle={{
      fontFamily: 'RobotoRegular', 
      fontSize: 24, 
      color: '#00b0ff'
    }}
  >
    <Scene
      title='adsf'
      key='vehicle'
      component={Vehicle}
      titleStyle={{
        fontFamily: 'RobotoRegular', 
        fontSize: 24, 
        color: '#00b0ff'
      }}
    />
  </Scene>

</Tabs>

如果我在Profilo页面上并且我不会转到该Vehicle页面,我会使用Actions.vehicle()但我收到此错误:

Actions.vehicle() 不是函数

我已经尝试过这个解决方案,但这也不起作用我该如何解决这个问题?

一个propesed的结果snack如下: 在此处输入图像描述

标签: react-nativeexporeact-native-router-flux

解决方案


使用动作场景键将要求您的场景与您的其他场景处于同一级别,即vehicle场景不能是profile.

此外,您将需要一个Stack组件来容纳profilevehicle场景,以便您可以调用Actions.{key}以正确访问场景。

我在这里放了一份小吃供你玩。:)

建议的解决方案:

<Tabs
  key='tabbar'
  backToInitial
  onTabOnPress={() => {
    console.log('Back to initial and also print this');
  }}
  swipeEnabled
  hideNavBar={true}
>
  <Stack
    title='ProfiloStack'
    key='profileStack'
  >
  <Scene
    title='Profilo'
    key='profile'
    component={Profile}
    tabBarLabel='Profilo'
    icon={TabBarIcon}
    name='ios-person'
    titleStyle={{
      fontFamily: 'RobotoRegular', 
      fontSize: 24, 
      color: '#00b0ff'
    }}
  />
    <Scene
      title='adsf'
      key='vehicle'
      component={Vehicle}
      titleStyle={{
        fontFamily: 'RobotoRegular', 
        fontSize: 24, 
        color: '#00b0ff'
      }}
    />
  </Stack>
</Tabs>

推荐阅读