# Ionic 5  navigator\['app'\].exitApp();

**URL:** <https://forum.ionicframework.com/t/ionic-5-navigator-app-exitapp/201387>\
**Category:** Ionic Angular\
**Created:** [December 16, 2020, 8:10pm UTC](https://forum.ionicframework.com/t/ionic-5-navigator-app-exitapp/201387 "2020-12-16T20:10:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhoyos](https://avatars.discourse-cdn.com/v4/letter/l/13edae/32.png) [@lhoyos](https://forum.ionicframework.com/u/lhoyos)\
**Post date:** [December 16, 2020, 8:10pm UTC](https://forum.ionicframework.com/t/ionic-5-navigator-app-exitapp/201387/1 "2020-12-16T20:10:39Z")

</div>

Good afternoon, I would like to know how I could fix the issue of closing the session in ionic 5 with capacitor, I am placing the following function and it has not worked for me, it does not enter the foreach.

backButtonEvent() {

```
this.platform.backButton.subscribeWithPriority(1, () => {

    this.routerOutlets.forEach((outlet: IonRouterOutlet) => {

        if (outlet && outlet.canGoBack()) {

            outlet.pop();

        } else {

             navigator['app'].exitApp();

        }

    });

});

```

}

---

<div class="post-metadata">

**Author:** ![dotman](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dotman/32/124290_2.png) [@dotman](https://forum.ionicframework.com/u/dotman)\
**Post date:** [December 17, 2020, 5:44am UTC](https://forum.ionicframework.com/t/ionic-5-navigator-app-exitapp/201387/2 "2020-12-17T05:44:41Z")

</div>

Amend your code to this and test

```auto
this.platform.backButton.subscribe(async () => {

            this.routerOutlets.forEach((outlet: IonRouterOutlet) => {
                if (outlet && outlet.canGoBack()) {
                    outlet.pop();
                } else {
                   navigator['app'].exitApp();
                }
            });
        });

```
