I’m having a hard time figuring out how do I pass data back to the previous page, by navigating back using the “< Back” button in the ActionBar?
Someone had the same question a while ago here: How to navigate between pages with data depending on each other?
The answer that was given is pointing to the docs. The problem there is that the docs explain navigation using the “navigate” method, where I create a context and pass that to the “navigate” function as the navigation context.
However, when you navigate TO a page, that page will already have a “< Back” button showing on the ActionBar automatically, and when I tap on that, it goes back to the previous page without me specifically calling the “navigate” function. That is what I’m interested in to find out. How do I prepare and pass the data back if I want to use the “< Back” button in the ActionBar, as opposed to using the “navigate” function?
Here’s a quick outline:
- contains a label
- tap the label to go to the next page
- you came here after you tapped the label on PAGE 1
- there’s a textfield on the page
- type something into the textfield
- tap the “< Back” button in the ActionBar to go back to PAGE 1
- the label on PAGE 1 will update using the string you entered into the textfield on PAGE 2
How do I pass the string in the textfield on PAGE 2 back to PAGE 1? I’m using JS only.
PS: I’ve read the PDF “The NativeScript Book” up until Chapter 8 which does have an example of this. Unfortunately the code doesn’t work and it’s crashing. But they also use the “navigate” function to go back to the previous page, as opposed to the “< Back” button in the ActionBar so that doesn’t help either.