Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Since React Router change from "query" to "search".
I use the following code to query from search
Query function:
setFilter(query) {
this.props.history.push({ pathname: this.props.location.pathname, search: query });
Search Parameter:
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);
But I get the following error:
Uncaught TypeError: location.search.charAt is not a function
How can I fix this problem?
–
–
–
Something else that worked for me is this:
setFilter(query) {
const searchParamsObject = new URLSearchParams(query);
this.props.history.push({ pathname: this.props.location.pathname, search: searchParamsObject.toString() });
As mentioned in comments. You need to remove query object to fix the issue
setFilter(query) {
this.props.history.push({ pathname: this.props.location.pathname});
//use query object here or wherever required
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.