I have three pages named as page1,page2 and page3
and their navigation will be page1->page2->page3
How we can identify on page2 that user came on this page via NavController Push or Pop function.
I just want to trigger a function on page2 only if they perform some action on page3 and redirected to page2 via navCtrl.pop() function.
I know i can put condition in ionViewWillEnter for last view name from nav stack, Because it will be fired everytime user be on page2. But If there is any other alternate or good way to do this. Please let me know
Thanks
Identifying if we came to a page using push
is easy as it is the standard way of passing a parameter from parent
to child
in navCtrl.push(PageName, parameters)
I think what you are asking is how to do the opposite: pass a value back from child
to parent
.
Below is a solution for this (see this link for details):
In parent, instead of the normal push
function, create a new promise, and in the then
part, you can get a parameter back from the child.
In child, after pop()
call its then
, and pass a parameter through the resolve of the promise that you initially created to the parent.
Parent
new Promise((resolve, reject) => {
this.nav.push(ChildPage, {resolve: resolve});
}).then(data => {
// process data
});
Child
this.nav.pop().then(() => this.params.get('resolve')('some data'))
I have used the above solution many times. There is also this alternative solution, but I haven't tested it myself:
https://forum.ionicframework.com/t/solved-ionic-navcontroller-pop-with-params/58104/3
我正在使用globalThis['datatoinput']
来输入我的数据,然后在我的父页面上使用ionViewDidEnter
来读取globalThis['datatoinput']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.