In the process of developing my very first hybrid mobile application using Ionic and AngularJS, I have encountered a challenge that I am currently trying to resolve. The issue at hand involves maintaining the state of the graphical user interface between navigations within the app. To provide context, let's assume that my mobile app features a side menu with various item links:
- Search form
- All (
#/all
) - Cats (
#/cats
) - Dogs (
#/dogs
) - Err... Cows? (
#/cows
) - Contact (
#/contact
)
The items listed from 2 to 5 trigger the retrieval of server data in an infinite loading fashion.
Now, let's consider a scenario where I navigate from Cats to Dogs, and then back to Cats. Due to my understanding that a new Controller instance (and scope) is created upon each route change, the app reloads the list of cats from the server instead of maintaining the previous state. My goal is for the Cats state to persist and be displayed again upon returning to it.
I have conducted research in search of a solution to this common dilemma, but most suggestions involve listening for events such as state change
or route change
and storing the object array in localStorage
. However, I find this approach somewhat cumbersome, particularly due to the necessity of compiling HTML which could potentially slow down performance, especially when dealing with a large number of objects. Additionally, there are concerns about the viewport reverting to the top of the app.
Therefore, I seek insights on how others address this issue. Is there a form of navigation akin to the browser's back and forward buttons? How would you recommend tackling this particular challenge?