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

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();

        }

    });

});

}

Amend your code to this and test

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

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