admin管理员组文章数量:1400157
In the search page I'm using search queries. I want to skip changes in search queries and go back to the real previous page.
Now:
/page1 -> /page2 -> /page2?id=1 -> /page2?id=1&order=max -(back)-> /page2?id=1 -(back)-> /page2? -(back)-> /page1
What I want:
/page1 -> /page2 -> /page2?id=1 -> /page2?id=1&order=max -(back)-> /page1
In the search page I'm using search queries. I want to skip changes in search queries and go back to the real previous page.
Now:
/page1 -> /page2 -> /page2?id=1 -> /page2?id=1&order=max -(back)-> /page2?id=1 -(back)-> /page2? -(back)-> /page1
What I want:
Share Improve this question asked Jun 24, 2018 at 7:55 alirezaalireza 5466 silver badges17 bronze badges 2/page1 -> /page2 -> /page2?id=1 -> /page2?id=1&order=max -(back)-> /page1
-
you can try
https://www.npmjs./package/url
and create a URL with differentpathname
but with same query string – Daniel Krom Commented Jun 24, 2018 at 7:59 - 1 @DanielKrom I want to go back in history of react-router it be possible not going to another page. I just want to skip query changes – alireza Commented Jun 24, 2018 at 8:04
2 Answers
Reset to default 5The pages you want to skip just use replace for navigation than push for them.
Let say your history stack is
/page1 Push another page /page2 Push another page /page3 Then there is only a query change on page3 and you want to go back to page2 on pop.
So just replace the /page3/ with /page3?q=test
So now the history stack will be
/page1
/page2
/page3?q=test
On the query params changes, you can use history.replace instead of history.push. So your URL changes in that scenario will not be pushed into the history stack.
this.props.history.replace(`${URL_TO_BE}${QUERY_STRING}`)
// this.props.history.push(`${URL_TO_BE}${QUERY_STRING}`)
本文标签: javascriptReactRouter skip search queries on back button pressStack Overflow
版权声明:本文标题:javascript - React-Router skip search queries on back button press - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744210876a2595411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论