Reputation: 2220
We have an Ionic app where we want to add a new feature in native. So clicking a button in the app, will launch a plugin just like normal plugins with it on UI etc. However complication comes when I want to navigate freely back and forth from plugin side to Ionic.
Consider these scenarios:
HTML page
written on Ionic side based on a user
action. Clicking back on this html page will again land you back to plugin UI.back stack
in Ionic and Android/iOS side so that back navigation happens smoothly.What I did so far is to use sendPluginResult
method to pass different codes to Ionic side and open desired pages. In reality it destroys the back stack totally since plugin has exited.
Clicking back button on Ionic side, I actually make plugin method calls again kind of emulating back behavior.
Is there a better way to handle this? Has someone faced similar problems?
Upvotes: 1
Views: 93
Reputation: 4246
I hope that I understood your question correctly.
Assuming that you can use some variable to check whether this plugin just opened a html-page, you could do something like this:
$ionicPlatform.registerBackButtonAction(function(event) {
if(/* check if plugin just opened html-page here */){
// if condition succeeds, then do not open same html-page again
event.preventDefault();
// go two steps backwards to prevent this plugin to open same html-page again
history.go(-2);
// update your variable
// ...
}
},100);
Hope it helps.
Upvotes: 1