小编Omr*_*Ram的帖子

将参数从堆栈导航器传递到选项卡导航器(反应导航 5)

我试图将用户 ID 从登录屏幕传递到作为嵌套选项卡导航器一部分的主屏幕。这是我的应用程序的结构:

 const mainStack = () =>(

             <Tab.Navigator


             tabBarOptions={{
              activeTintColor: 'tomato',
              inactiveTintColor: 'gray',
            }}
             >
                <Tab.Screen name="Home" component={Homescreen} 
                 options = {{headerStyle: {backgroundColor: 'yellow'}}}
                />
                <Tab.Screen name="Profile" component={otherStack} />
             </Tab.Navigator>

    )




export default () => (

        <NavigationContainer >
              <Stack.Navigator screenOptions={{
                  headerShown: false
                  }}>
                <Stack.Screen name='Welcome' component={WelcomeScreen} />
                <Stack.Screen name = 'Register' component = {RegisterScreen} />
                <Stack.Screen name= 'Login' component={LoginScreen} />
                <Stack.Screen name = 'mainStack' component={mainStack} />
              </Stack.Navigator>



        </NavigationContainer>

)
Run Code Online (Sandbox Code Playgroud)

每当我从登录屏幕转到主页并调用 this.props.navigation.getParam('id') 时,我都会收到一条错误消息,指出它不是一个函数。仔细检查后,我发现 this.props.navigation.state 是未定义的。可能意味着我的参数不会传递到主屏幕,即使我导航到它没有任何问题。

我尝试使用 NavigationActions 但我收到一个错误,我在其他任何地方都没有提到。

我像这样导航到主页:

this.props.navigation.navigate('Home' { …
Run Code Online (Sandbox Code Playgroud)

javascript react-native redux react-navigation-stack react-navigation-bottom-tab

2
推荐指数
1
解决办法
2358
查看次数