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'(不工作
-
确保
this
指向组件而不是函数本身。 -
哪个版本的react导航?
NavigationContainer
、Stack.Navigator
、Stack.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
}
.....
}