Home > Back-end >  Back to previous page instead of previous url in next js
Back to previous page instead of previous url in next js

Time:11-14

I faced a problem where I have some filters on a page. When you filter, the page URL will change and the query string will add to the end of the URL.So when you click on the back button, the page will stay on the current page and will back to the previous query string. What I want is to get back to the previous page which is come from that to the current page. For example, I am on /home page, then I go to /browse page, then I filter some items and my URL will /browse?subject=2 and I filter again and the URL will be changed to /browse?subject=2&vendor=2. Now I want to the previous page (I mean /home), when I click on the back button I will go to /browse?subject=2. I hope I have conveyed what I mean.

CodePudding user response:

What you need to do is in you /browse page when you are filtering use router.replace instead of router.push in this way, your filter result won't be added into the browser history and when you try to use router.back you would go to the previous page.

  • Related