首页 > 解决方案 > 如何在 StackActions 中发送参数 - React Native

问题描述

我正在尝试使用StackActions. 页面导航成功,但没有收到相应的已发送参数。

主屏幕:

reLogin = () => {
    this.props.navigation.dispatch(StackActions.reset({
        index: 0,
        actions: [
            NavigationActions.navigate({
                routeName: 'Login'
            },
            { 
                forceLogin: true <<-- This Flag Is Set Here
            }),
        ],
    }))
}        

登录屏幕:

没有错误,但在LoginScreen'scomponentDidMount()中,下面的代码总是返回 false。

componentDidMount() {
    alert(this.props.navigation.getParam('forceLogin', false))
}

我错过了什么?

标签: reactjsreact-native

解决方案


文档中,您需要传递参数对象,例如,

NavigationActions.navigate({
        routeName: 'Login',
        params : { forceLogin: true }
})

推荐阅读