由于React Router从“查询”更改为“搜索”。我使用以下代码从搜索中查询
查询功能:
setFilter(query) {
this.props.history.push({ pathname: this.props.location.pathname, search: query });
}
搜索参数:
applyFilter() {
const newFilter = {};
if (this.state.content) {
newFilter.content = this.state.content;
}
if (this.state.fromDate) {
newFilter.fromDate = this.state.fromDate;
}
if (this.state.toDate) {
newFilter.toDate = this.state.toDate;
}
this.props.setFilter(newFilter);
}
但是我收到以下错误:
Uncaught TypeError: location.search.charAt is not a function
我该如何解决这个问题?
如评论中所述。您需要删除查询对象以解决问题
setFilter(query) {
this.props.history.push({ pathname: this.props.location.pathname});
//use query object here or wherever required
}
您必须按照docs上的说明将字符串传递给搜索属性,而不是对象