Answer the question
In order to leave comments, you need to log in
How to update url after API request?
I'm using react-router-dom.
The bottom line: a request is made to the API, after receiving the response, everything is displayed, but it is necessary that after receiving the response, the url link is updated. Since the page uses pagination, when you click on each button on the page, the url should change. So that later there was access by url to each page. How to do it?
At first I wanted to use history.pushState(), but I realized that when using react-router-dom this is redundant.
Now I do this:
*A request is executed*
*An answer
is received* The request
itself is written into a constant and it is substituted into NavLink and Route. But nothing comes out.
Example:
app.js
const link = props.link // в props.link приходит: `?q=+language:&sort=stars&order=desc&page=1&per_page=10`
<Route path={link} />
<input />
<NavLink to={props.link}><button>Search</button></NavLink>
TypeError: Cannot read property 'pathname' of undefined
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question