Answer the question
In order to leave comments, you need to log in
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¶m2=2'
let history = useHistory();
useEffect(() => {
history.push(query);
}, [query]);
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question