0

We have a "Search" ui-router state, which can be accessed from menu. It returns a list of results in that state. Then from the search, the user can click an individual item they found and go to an "individual item view state" for lack of a better description.

Right now, if the user uses the browser back button (I guess it's really a "history back" button?) and goes back to the previous state, the search controller runs anew. As far as I understand, and correct me if I am wrong, using back is basically like reloading a state from scratch.

The requirement for the project is to have the search populate with previous search criteria, BUT only if the user accesses it through the back button, not the menu.

I read this answer which basically tracks all state history and checks for $state history in a particular order to decide if the back button was used. That's great, but we have hundreds of states. Is there some other way?

Community
  • 1
  • 1
VSO
  • 11,546
  • 25
  • 99
  • 187
  • 1
    The easiest route to go would be to off-load your search criteria as route-parameters. These will be restored when navigating "back" and you can enforce a "clean" route through your menu clickhandlers. – kasoban Dec 01 '15 at 14:16
  • Thanks kaso, that's what I am leaning toward too now. – VSO Dec 01 '15 at 14:18
  • Edit: Though I probably won't use route params. Will probably save search criteria in a service and clear that service on navbar navigation to state. If empty, do a blank search, if not, search by criteria saved in local storage. – VSO Dec 01 '15 at 14:25
  • 1
    That's possible too, but with the route params you can also support stepping back through multiple different searches, instead of just managing a search state singleton – kasoban Dec 01 '15 at 15:56
  • 1
    Btw. you can also have state params that are not part of your url. – Namoshek Dec 01 '15 at 16:32

0 Answers0