Nativescript block "loaded" Event when Back button clicked from new Page


#1

Sir,
I am using Nativescript core with javascript. Now I want to prevent the pageload event when the user came back from next page. Because it causes, reloading the last page again. Does anybody have any idea about the same???

Thank You


#2

The underlying native views will be cached and reused when added back on screen (while navigating back to a page), loaded event will be triggered so it can relayout, apply styles etc.,

Do you have any specific reason you don’t want this to happen? Still you can fix it simply in your code, for example setting binding context only on first loaded event.

export onPageLoaded(args) {
 const page = event.object;
 if(!page.bindingContext){
  page.bindingContext = new MyViewModel();
 }
 // You can even remove the listener here to prevent another loaded event call on back navigation
 page.off(Page.loadedEvent);
}

#3

thank you so much sir…