【发布时间】:2021-02-19 15:22:59
【问题描述】:
我正在将另一个页面的道具传递到这个页面,它工作正常。所以我决定把接收页面的路由复制到另一个tab,所以就抛出了这个错误:
TypeError: Cannot read property 'myData' of undefined
这是可以理解的,因为没有传递任何道具。我想要做的是路由到另一个页面,因为下面的代码行没有定义任何道具:
componentDidMount() {
this.props.location.state.myData === undefined && this.props.history.push('/');
this.fetchData(data);
}
但它不起作用,它给了我与上面相同的错误。我可能做错了什么以及如何解决这个问题?
【问题讨论】:
-
你在使用 React 路由器吗?你能在路由规则而不是子组件中应用这个逻辑吗?
-
瑞恩,你是什么意思?
标签: javascript reactjs routes react-router-dom