使用: "@react-navigation/drawer": "^5.4.0", "@react-navigation/native": "^5.1.4",
应用程序.js:
import { createDrawerNavigator } from '@react-navigation/drawer';
...
const Drawer = createDrawerNavigator();
const DrawerRender = () => {
return (
<NavigationContainer>
<Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="Screen1" component={Screen1} options={{unmountOnBlur: true, gestureEnabled: false}} />
<Drawer.Screen name="Screen2" component={Screen2} options={{unmountOnBlur: true, gestureEnabled: false}} />
</Drawer.Navigator>
</NavigationContainer>
);}
从屏幕 1:
navigateToPage = page_id => {
this.closeCommentScreen();
this.reopenModal = true;
this.props.navigation.navigate('Screen2', {'page_id': 'testing'});
}
在屏幕 2 上:
export default class Screen2 extends React.Component {
constructor(props) {
super(props);
}
componentDidMount() {
let id = this.props.navigation.state.params.page_id
...
我尝试打印“this.props.navigation”,它总是返回空字典 {},因此 params 未定义。
我究竟做错了什么?
它是 this.props.route.params
请参阅升级指南https://reactnavigation.org/docs/upgrading-from-4.x#separate-route-prop
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句