GoBack Not Preserving state




The goBack method doesnt preserve the state of the previous page. To elaborate, I have created an example https://play.nativescript.org/?template=play-tsc&id=oyM8O7&v=3.

  1. On the page 1, tap on change button and label changes to “Bye”.
  2. Click on Second Page Button and you will be taken to another page.
  3. If you click on Go Back button then you will be taken back to Home page again.
  4. However, the home page still shows “Hi” but you had left it as “Bye”.

Is there an easy way to preserve the state while navigating back using topmost().goBack();



I think that when you goBack to Home page , loaded method is called again
and it is loaded with its default value ‘Hi’
Maybe you could use something like in your changeIt method in home-page
like vm.set(‘description’, ‘Bye’);


Try now: https://play.nativescript.org/?template=play-tsc&id=oyM8O7&v=5

Use onNavigatingTo event.
And check if args.isBackNavigation is true. If yes then don’t initialize vm.