A
A
Alexander2021-10-11 02:00:03
React
Alexander, 2021-10-11 02:00:03

How to check for adding URL query params react-router-dom?

How to add new query params to URL string?
I have 4 types of query params, and I need them to be added one after the other when clicked, without ?, if it is already there at the beginning.

<p onClick={() => history.push('?sortBy=ASC')}>Featured</p>
<br />
<p onClick={() => history.push('?sortBy=DESC')}>Newest</p>
 <br />
<p onClick={() => history.push('?color=black')}>Black</p>
 <br />
<p onClick={() => history.push('?color=blue')}>Blue</p>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question