ravi sharma

ravi sharma

  • NA
  • 87
  • 15.5k

Browser back not working after search pagination change

Aug 8 2019 2:56 AM
Hi,
 
I am on home page and from there I am searching "Technical Support" in my global search. Now it's redirecting to search page. There we have following URL and On change of pagination and radio button, url hash and pagination is change only without reloading whole url.
 
1: Initial URL:
http://dev.abc.com
2: After global search:
http://dev.abc.com/search?query=Technical%20Support&index=0&size=25#all
3: Pagination Change: 
http://dev.abc.com/search?query=Technical%20Support&index=1&size=25#all
4: Radio button change
http://dev.abc.com/search?query=Technical%20Support&index=0&size=25#products
 
Now, on pagination change or radio button click, we have following code in jquery.
key: "updateBrowserHistory",
        value: function updateBrowserHistory(obj, browserURL) {
            if (Object.keys(obj.params).length > 0) {
                browserURL = browserURL.replace(/\?*$/, '?');

                for (var i = 0; i < Object.keys(obj.params).length; i++) {
                    var key = Object.keys(obj.params)[i];
                    var value = obj.params[key];
                    browserURL += key + '=' + value;
                    if (i + 1 < Object.keys(obj.params).length) {
                        browserURL += '&';
                    }
                }
            } else {
                browserURL = browserURL.replace(/\?*$/, '');
            }

            if (obj.hash) {
                browserURL += "#" + obj.hash;
            }

            window.history.pushState({ 'html': '' }, '', browserURL);
        }
 
Now when I click on back or forword from browser, it's working fine for all ajax call where url is getting refresh only. But it's not going on step 1 from where we entered search text.
 
Please suggest.