Not getting previous state data in Angular js when user clicks on browser back button

163 Views Asked by At

I am working on an AngularJs application. My Problem is as Follows

I have a filtered data using certain parameters using checkboxes and radio buttons. After Filtering of the Data, I have moved to another state. When the user clicks on the back button on the browser, I am unable to get the filtered data. Instead of that I am getting a generalized state data.

Eg.

I have list of professionals and m applying filter based on age and gender to get particular professionals and after getting result of filter if click on any result i m redirected to a new state that is the detail view of that professional.. now if i click on back button of browser i m getting list of all professionals but i want my filtered list..

please help me out with this..

and this can be achieved if we pass some parameter in the state url at the time of applying filter.. but how to achieve this..??

Can anybody guide me on this ??

1

There are 1 best solutions below

2
On BEST ANSWER

Are your query parameters part of the URL? For example, I do paging and filtering in an application and my URL looks like this:

http://localhost:51923/#/accounts/search?searchText=account&pageSize=25&pageNumber=1&someBool=true&someBool2=false

Now, the state in UI Router that maps to this looks like so:

.state("accounts.search", {
    url: "/search?searchText&pageSize&pageNumber&someBool&someBool2",
    params: {
        searchText: { value: "", squash: true },
        pageSize: { value: "25", squash: true },
        pageNumber: { value: "1", squash: true },
        someBool: { value: "false", squash: true },
        someBool2: { value: "false", squash: true }
    },
    controller: "accountsController as vm",
    templateUrl: "site/accounts/search/accounts.html",
    data: { pageTitle: "Accounts" },
    resolve: { //...resolve data here... },
    someOtherStuffIfNeeded: { //stuff here} 
    }
})

Have a look at the documentation for ui router taking not of the state params section which explains default values and what squash does. Its IMPORTANT to note that the params are strings (notice false is "false"). Hope this helps.