N
N
n1ksON2020-12-25 19:09:50
React
n1ksON, 2020-12-25 19:09:50

How to change url dynamically and implement react-router-dom transition?

The site has a search. When you click on the button, a redirect to another page should occur, the url of which depends on the search parameters (url like: /search?param1=1¶m2=2)
To navigate, I want to use react-router-dom, but I don’t understand how.

Here's what I was able to do:

const query = props.state.query; // изначально '/home', потом меняется на строку вида: '/search?param1=1&param2=2'
let history = useHistory();
useEffect(() => {
   history.push(query);
}, [query]);

It works incorrectly.

I saw different things in the react-router dock

, but I didn’t come up with a solution And so, how to change the url that would match the search query?
Button click --> Form url --> Change url and open another Route

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Makarov, 2020-12-26
@kirbi1996

Well, as the easiest option, create a default state that will be your link and mutate it through setState, the rest you have already written, though I don’t know how good this solution is. But I think if you write a question in English in Google, you will quickly find a solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question