Reputation: 33
BG: I got 2 page and want to switch to each other every 60 seconds.
now i am using push/pop to do the job. when i push the second page it will create a new one and the page would flicker which had a bad user experience. when i pop to the first page. it works just fine.
Q: how can i navigate to certain page with the page cached. and i've searched the NavController and i did not find any api could help.
thanks a lot
Upvotes: 0
Views: 305
Reputation: 388
You can use nav.push('AboutPage')
for pusing your previous page to cache. Use nav.pop()
to clear top cache value and go back to previous page. User nav.setRoot('AboutPage')
to clear the cache and start from begining.
Upvotes: 1
Reputation: 2007
Maybe this example helps to visualize this:
1. Initial state after startup:
[HomePage]
2. State after nav.push('AboutPage'):
[HomePage, AboutPage]
^^^^^^^^
cached
3. State if you use the navbar to navigate back or pop():
[HomePage] // The cached instance is used so ionViewDidLoad() is not called
4. State if you use .push('HomePage') after the second step:
[HomePage, AboutPage, HomePage] // a new instance is created so ionViewDidLoad() is called
^^^^^^^^ ^^^^^^^^^
cached cached
Ionic 2.x are use this process and its a standard process.
inspired form stackoverflow question
Upvotes: 0