title: Is there a way to catch and cancel the back button event in a NativeScript app on the iOS platform?
body: <p>I'm working on a NativeScript-Angular app for both Android and iOS but have hit a problem with standard back button navigation. I have resolved the issue for Android, but cannot find a solution for iOS.</p>
  
  <p>The event is causing a problem when going back to a particular page where routing data is expected, resulting in the exception: </p>
  
  <blockquote>
    <p>"Error: Currently in page back navigation - component should be reattached instead of activated". </p>
  </blockquote>
  
  <p>My Android solution catches the back button event and cancels it, then calls the router to do the navigation. </p>
  
  <pre><code>
   ngOnInit() { 
       if (app.android) {
         app.android.on(app.AndroidApplication.activityBackPressedEvent, 
           (args: any) =&gt; this.backEvent(args));
       }
   }
  
   backEvent(args) {
     args.cancel = true; 
     this.backToRegister(false);
   }
  
   backToRegister(accepted: boolean){
     this.router.navigate(['/register', 
       this.registerParametersEntered.password, 
       this.registerParametersEntered.confirmPassword, 
       this.registerParametersEntered.code, 
       this.registerParametersEntered.email,
       accepted]);
   }
  </code></pre>
  
  <p>I want to do something similar with iOS, such as: -</p>
  
  <pre><code>if (app.ios) {
    this.page.on('navigatingFrom', (data) =&gt; {
      // TODO cancel the back button event
      this.backToRegister(false);
    })
  }
  </code></pre>
  
  <p>I can't find a way of doing this for iOS - my research is leading me to the conclusion it is not possible to cancel the iOS back button - for example, see <a href="https://stackoverflow.com/questions/41863216/nativescript-behavior-of-the-go-back-button/41871549#41871549">here</a>.</p>
  
  <p>Any ideas or alternative suggestions greatly appreciated!</p>