Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nativescript | call ngOnInit after android back button Navigation

I have a problem handling the back button , when the user taping the back button the ngOnInit is not triggered and the component is not working as wanted . from what i saw i understand that when taping back its only make the ngOnDestroy fire but not the ngOnInit

this is the lifecycle

open App --> ngOnInit() called

click on some anther component --> ngOnInit() of the new component called

tap back --> ngOnDestroy

Did someone had the same problem and how did you handle it ? thank you

like image 218
Matan Shushan Avatar asked Aug 24 '26 00:08

Matan Shushan


1 Answers

After some search i decided to use this solution

in components that i need the ngOnInit to run even if the navigate is from the back button or function i added this

constructor(private location : PlatformLocation) {}

ngOnInit() {
    this.location.onPopState(() => {
    this.initComponent();
});
}
like image 186
Matan Shushan Avatar answered Aug 25 '26 15:08

Matan Shushan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!