G
G
gorwhoami2020-08-15 16:23:11
React
gorwhoami, 2020-08-15 16:23:11

Why doesn't history.push work correctly?

Hello. There is a list of movies with pagination. When I try to switch between pages, the following entry appears in the uri How can I solve this problem? Here is the whole pagination code. I use ant design

?page=4&page=3&page=2 И т.д

const location=useLocation();
        const history = useHistory();
        const onChange=(pageNumber)=>{
        const parsed = queryString.parse(location.search);
        if(!pageNumber){
            pageNumber=1;
            props.getAllMovies(pageNumber,queryString.stringify(parsed));
        }else {
            props.getAllMovies(pageNumber,queryString.stringify(parsed));
            if(queryString.stringify(parsed)) {
                history.push(`/?page=${pageNumber}&${queryString.stringify(parsed)}`)
            }else {
                history.push(`/?page=${pageNumber}`)
            }
        }

To send a request by url, I use queryString.parse (location.search)
I think the problem is in it. But it is needed in order to search for a movie by filters.

And without queryString it will not work
. page=3 &genres=12& page=2 &rating=5&year=2004%2C2020 Tell me
how you can solve the problem

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