import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { Location } from '@angular/common'; import { AlertController } from '@ionic/angular'; @Injectable({ providedIn: 'root' }) export class RouterService { constructor( private alertController:AlertController, private location:Location, private router:Router ) { } navByUrl(url:string){ this.router.navigateByUrl(url); } goBack(){ this.location.back(); } Router(){ return this.router; } async exitApp() { let alert = await this.alertController.create({ header: 'Attention' , mode: 'ios', message: 'Are You Sure Want to Exit?' , buttons: [ { text:'Cancel' , role: 'cancel', handler: () => { } }, { text: 'OK' , handler: () => { navigator['app'].exitApp(); } } ] }); alert.present(); } }