如何在react native中从导航中获取参数值


this.props.navigation.navigate("ProductDeatils",
{params:{ price: this.state.GridListItems.price,
url: this.state.GridListItems.url} 
});
I wanted to display these params values on the "ProductDeatils" page. please can anyone help me?

this.props.navigation.params未定义。我试过这个const{navigation}=this.ops;const id=navigation.getParam('price'(不工作

  1. 确保this指向组件而不是函数本身。

  2. 哪个版本的react导航?NavigationContainerStack.NavigatorStack.Screen配置好了吗?

示例:

App.js

<NavigationContainer>
<Stack.Navigator
initialRouteName="Splash"
screenOptions={{
headerShown: false,
}}>
<Stack.Screen name="Login" component={Login} />
.......

Login.js

export default class Login extends React.Component {
componentDidMount() {
console.log(this.props.navigation) // It should work
}
.....
}

最新更新