# How to stop page leave

**URL:** <https://forum.ionicframework.com/t/how-to-stop-page-leave/44150>\
**Category:** ionic-v3\
**Created:** [February 19, 2016, 1:11am UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150 "2016-02-19T01:11:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lastmj](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/lastmj/32/84886_2.png) [@lastmj](https://forum.ionicframework.com/u/lastmj)\
**Post date:** [February 19, 2016, 1:11am UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150/1 "2016-02-19T01:11:44Z")

</div>

I want to stop a page transition from within the onPageWillLeave hook. I want to perform some validation there, and then stop the user from leaving if the validation fails. Is this possible currently? Is there a better way that I should be aware of? Thanks!

---

<div class="post-metadata">

**Author:** ![arjenbroeze](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/arjenbroeze/32/94963_2.png) [@arjenbroeze](https://forum.ionicframework.com/u/arjenbroeze)\
**Post date:** [February 19, 2016, 7:41am UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150/2 "2016-02-19T07:41:53Z")

</div>

If you don’t rely on default navigation but do your navigation in your controller it’s easy.

For example, if you want to be able to control whether or not the back-button at the top of the screen goes back to the previous view, you could just define a new back-button in your template and handle the on-click for that button. An example:

The template:

```
<ion-view view-title="MyView">
    <ion-nav-buttons side="left">
        <button class="button button-clear icon ion-ios-arrow-back" ng-click="goBack()">Back</button>
    </ion-nav-buttons>
    <ion-content class="padding">
    ....
    </ion-content>
</ion-view>

```

In your controller:

```
 $scope.goBack = function()
 {
    if (inputIsValid()) {
       $ionicHistory.goBack();
    }
    else {
       alert("There's something wrong with your input");
    }
 };
```

---

<div class="post-metadata">

**Author:** ![lastmj](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/lastmj/32/84886_2.png) [@lastmj](https://forum.ionicframework.com/u/lastmj)\
**Post date:** [February 19, 2016, 1:57pm UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150/3 "2016-02-19T13:57:06Z")

</div>

Thanks for your reply. I’m handling navigation in a separate component, a primary bar component, which is separate from the current component controller on screen, so this solution is not ideal for me. Also, I’m using Ionic 2.

---

<div class="post-metadata">

**Author:** ![1114](https://avatars.discourse-cdn.com/v4/letter/1/77aa72/32.png) [@1114](https://forum.ionicframework.com/u/1114)\
**Post date:** [June 2, 2016, 7:48am UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150/4 "2016-06-02T07:48:43Z")

</div>

@lastmj Excuse me,Did you solve this problem?

---

<div class="post-metadata">

**Author:** ![iignatov](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/iignatov/32/100112_2.png) [@iignatov](https://forum.ionicframework.com/u/iignatov)\
**Post date:** [June 2, 2016, 6:15pm UTC](https://forum.ionicframework.com/t/how-to-stop-page-leave/44150/5 "2016-06-02T18:15:24Z")

</div>

I just wanted to mention that there’s an open issue about this, in case that someone finds this topic:

> <https://github.com/ionic-team/ionic/issues/6623>
