我仍然是新的反应导航. 我想在登录成功后重置路由信息.但是有一些参数,比如我希望传递给主页面的登录信息. import { NavigationActions } from 'react-navigation'const resetAction = NavigationActions.res
我想在登录成功后重置路由信息.但是有一些参数,比如我希望传递给主页面的登录信息.
import { NavigationActions } from 'react-navigation' const resetAction = NavigationActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: 'Profile', params:{user:this.state.username}}) ] }) this.props.navigation.dispatch(resetAction)
在Profile页面中,我想访问params,所以我使用它:
constructor(props){ super(props) this.state = { username: this.props.navigation.state.params.user, }
但我收到:undefined不是控制台日志中的对象(评估’_this.props.navigation.state.params.user’).
我可以知道如何获取参数?谢谢
const resetAction = NavigationActions.reset({ index: 0, actions: [ NavigationActions.navigate({ routeName: 'ScreenName', // name of the screen you want to navigate params: { paramsKey: paramsValue // this second parameter is for sending the params } }) ], }); this.props.navigation.dispatch(resetAction);
并从导航状态参数获取第二个屏幕中的参数值,如下所示: –
static navigationOptions = ({navigation, screenProps}) => { const params = navigation.state.params || {}; // You can get the params here as navigation.state.params.paramsKey console.log("CompareScreen product_id:", params.paramsKey); }