【发布时间】:2021-09-16 06:04:22
【问题描述】:
我正在学习 React Native,对此没有太多经验。 我正在尝试在 App.js 文件中导航,它在此行给出“TypeError:无法读取未定义的属性 'navigate'”:this.props.navigation.navigate("BlogScreen", {"postId": notification.data .post_id}); 我已经尝试调试它,也尝试了一些已经询问过类似问题的解决方案,但似乎没有一个有效。我认为这些问题和我的区别在于导航代码是写在我的“App.js”文件中的。 如果能得到任何帮助,我将不胜感激。
来自 package.json 的一些配置信息:
"@react-navigation/native": "^5.9.3",
"@react-navigation/stack": "^5.14.3",
"axios": "^0.21.1",
"react": "16.13.1",
"react-native": "0.63.4",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
以下是我的 App.js 文件
import React, { Component } from 'react'
import AppNavigation from "./app/src/appnavigation/AppNavigation"
import { Provider } from 'react-redux'
import Store from './app/src/redux/store/Store'
import { MenuProvider } from 'react-native-popup-menu'
import FCMServices from "./app/src/utility/PushNotificationHandler"
class App extends Component {
componentDidMount() {
let obj = FCMServices.getInstance(this.FCMServiceCallback);
obj.setNavigationInstance(this.props.navigation);
obj.register(this.onRegister, this.onNotification, this.onOpenNotification)
}
FCMServiceCallback = () => {
console.log("FCMServiceCallback")
}
onRegister = (fcmToken) => {
console.log(fcmToken, "fcmToken")
}
onNotification = (notification) => {
console.log(notification, 'notificationnotificationnotification')
}
onOpenNotification = (notification) => {
this.handleNotificationsClick(notification)
}
handleNotificationsClick = (notification) => {
if (!notification.data) {
return;
} else {
this.props.navigation.navigate("BlogScreen", {"postId": notification.data.post_id});
console.log(notification, 'notificationClicked')
}
}
render() {
return (
<Provider store={Store}>
<MenuProvider>
<AppNavigation />
</MenuProvider>
</Provider>
);
}
}
export default App
【问题讨论】:
标签: android react-native navigation react-navigation