My app tends to have a deep navigation stack (dozens of pages on a normal browsing session) and users expect the app to restore completely each time they load it up. As noted elsewhere online the OS may kill your app when in the background and when it does the app will have to do a fresh start the next time the user loads it, losing the browsing history from the last session. As far as I can tell Ionic doesn’t have a built-in way to persist app state between sessions (at least it didn’t in v1, that may be changing in v2) so it’s up to me to build a solution for my app.
My question is how do I go about doing this? At a high level it seems like each time the navigation stack changes I want to write the current app state (at least the stack of pages) to a permanent storage (probably using
SqlStorage). I know I can use
NavController.getByIndex() to get each of the view controllers for the current stack but how would I go about saving and restoring those? I can imagine manually collecting the relevant state data from each of the pages and then using
NavController.insertPages() to rebuild the stack at startup. While that seems viable it also feels like a hack. Does anyone have experience with this? Is there a better way to persist app state between sessions?