这是我的路由器层次结构:
<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()不是函数
我已经尝试过此解决方案,但这也行不通。如何解决此问题?
使用动作场景关键点将要求您的场景与其他场景处于同一级别,即,该vehicle
场景不能是的子组件profile
。
另外,您将需要一个Stack
组件来容纳profile
和vehicle
场景,以便可以调用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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句