使用 React 和 Javacript,props.location
在通过时添加自定义属性是否可以接受props.history.push
?例如
this.props.history.push({
pathname: '/someurl',
state: {smallObject: myObject},
customProperty : myBiggerObject
});
然后在 /someurl 加载的组件上,我可以加载:
let myBigObj = this.props.location.customProperty;
这似乎可行,我在问这样做是否“可以”?我担心我可能会忽略 Javascript 或 React 中我不知道的某些内容。
如果我传递的对象足够小,我会在 state 属性中传递 customProperty。不是:它超过了此处myBiggerObject
提到的 640k 限制,并且我收到一条错误消息,表明如果我传入该state
属性,则无法克隆数据。