reactjs - 刷新页面我得到 TypeError: Cannot read property 'Location' of undefined
问题描述
您好,我有一个反应应用程序,它运行良好。所有路线,页面加载。一切都很完美。但是,当进入 FarmProperty 页面并尝试重新加载它 (F5)时,TypeError: Cannot read property 'tenant_account' of undefined
会发生错误。
FarmProperty.js
import { connect } from 'react-redux';
import * as actions from '../../store/actions/farmProperty';
class FarmProperty extends Component {
state = {
page: 0,
limit: 15,
msg: "",
erro: "",
success: "",
loading: false,
openModal: false,
id_delete: "",
tenant_account_id_delete: "",
apiData: false
}
componentDidMount() {
this.getFarmProperties();
}
componentDidUpdate(nextProps) {
if (!this.props.user && nextProps.user) this.getFarmProperties();
this.receiveApiData();
}
getFarmProperties() {
const { page, limit } = this.state;
const { farm_properties, user } = this.props;
//console.log(user);
this.props.getFarmProperties(user.tenant_account.id, page, limit);
if (this.props.location.state) {
this.setState({ msg: this.props.location.state.msg });
this.props.location.state.msg = "";
}
if (farm_properties === "undefined") return null;
}
receiveApiData() {
if (typeof this.props.farm_properties !== "undefined" && this.props.farm_properties !== null
&& !this.state.apiData && this.props.farm_properties.data.currentPageNumber === this.state.page) {
this.setState({ apiData: true });
}
}
render() {
return (
<>
</>
)
}
}
const mapStateToProps = state => ({
farm_properties: state.farmProperty.farm_properties,
user: state.auth.user
})
export default connect(mapStateToProps, actions)(FarmProperty);
我相信问题出在功能上
this.props.getFarmProperties (user.tenant_account.id, page, limit);
当我传递user.tenant_account.id
参数时。这个参数是登录到应用程序的用户,我需要获取这些信息,但是如果有其他方法可以获取这些信息,我将不胜感激。
解决方案
推荐阅读
- android - 全屏 TYPE_ACCESSIBILITY_OVERLAY
- python - keras 中 ResNet50 进行迁移学习时,损失总是归于 nan
- nginx - Nginx:如何在通过代理传递它们之前将发布数据编码从 UTF-8 转换为 TIS-620
- sql - ingres 10s sql 行号
- linux - 未在 weblogic linux 中打印的日志
- javascript - 在 forceNetwork 中为 networkD3 更改图例文本的颜色
- android - 在 RelativeLayout 上未检测到滑动
- java - 如何在 Bazel BUILD 中使用 gradle 的 apply 插件?
- patch - “不支持 git 二进制差异”错误使用 yocto
- angular - 错误 TS2339:“FormData”类型上不存在属性“条目”