How can I force a page refresh/reload after a router.navigate ?
I asking because ngOnInit works only once and if I have to return to a previous page using router.navigate the displayed data are not updated.
I have also tried with all Angular life cycle hooks but I can’t find the best way to to that, I have also tried with {reload: true} without success.
Some of the Ionic lifecycle events are equivalent to Angular lifecycle hooks. For example, ionViewDidLoad() fills the same role as the Angular OnInit lifecycle hook ( ngOnInit() ). In such cases, use the Angular lifecycle hook.
OnInit still runing only once and the other lifecycle events (like ngAfterContentInit, ngAfterContentChecked…) are fired a lot of times after router navigate.
The problem persist.
What I Trying to do? I have 3 pages:
A: Panel with statistics
B: List with all records
C: New record page
From A to B data is loaded correctly after router.navigate
but From C returning to B the data list is not updating.
In B page I have on OnInit a function that get data from database, but it only works when I load B page at first time (from A to B), not after create a new record on page C, on Page C After save the new record I have a router.navigate that redirects to B page again, it’s very simple but it’s nor working like the expected.
I would come at this from a different angle. Instead of actually doing data updating in ngOnInit, instead subscribe to an Observable that always provides the most recent data. Correspondingly, unsubscribe in ngOnDestroy. That way, you don’t ever have to care about “forcing” anything.
I have an idea to do that.
i have create a param for that page which i want to referesh.
and i have redirected back to page with a random param. and it treated it as a new page.
{
path: 'clubhome/:referesh',
loadChildren: () => import('./clubhome/clubhome.module').then( m => m.ClubhomePageModule)
The solution from peerodeveloper solved my problem. I had an infinity scroll user list with a filter. When I opened the filter window, the filter should be applied to the user list immediately without the user having to reload the page. With this solution it works.