React Router V4 - Uncaught TypeError: location.search.charAt is not a function
由于React Router从"查询"更改为"搜索"。
我使用以下代码从搜索查询
查询功能:
1 2 3 | setFilter(query) { this.props.history.push({ pathname: this.props.location.pathname, search: query }); } |
搜索参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 | 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); } |
但是我收到以下错误:
1 | Uncaught TypeError: location.search.charAt is not a function |
我该如何解决这个问题?
您必须按照文档中的说明传递字符串以搜索属性,而不是对象
如评论中所述。 您需要删除查询对象才能解决此问题
1 2 3 4 | setFilter(query) { this.props.history.push({ pathname: this.props.location.pathname}); //use query object here or wherever required } |