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:

/page1 -> /page2 -> /page2?id=1 -> /page2?id=1&order=max -(back)-> /page1

Share Improve this question asked Jun 24, 2018 at 7:55 alirezaalireza 5466 silver badges17 bronze badges 2
  • you can try https://www.npmjs./package/url and create a URL with different pathname 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
Add a ment  | 

2 Answers 2

Reset to default 5

The 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