我试图在我的应用程序中的两个全状态组件(餐厅ID)之间传递一个参数,第一个是我的登录组件,我这样做。
onPressLogin = () => {
loginService(this.state.email, this.state.password)
.then((res) => {
this.props.navigation.navigate('Commandes', {id:res.data.restaurant.id})
})
.catch((err) => {
console.log(err)
alert('Email/Password invalide')
})
}
而在我的第二个组件,主屏幕(屏幕:Commandes),我这样做。
componentDidMount() {
const {id} = this.props.route.params
this.getRestaurantInfo()
this.getRestaurantStatus()
this.getOrders()
this.setState({ isLoading: false })
}
但我有未定义,我检查了文档,他们只为无状态组件指定了......
我还检查了this.props.navigation.navigate的值,这是一个函数,以及显示这个路由的值。
route.params Object {
"key": "Commandes-kHfSvHgETC",
"name": "Commandes",
"params": undefined,
}
你可以试试这个
this.props.navigation.state.params.id
请检查 https:/reactnavigation.orgdocsparams。 再出来,确保你做得很好