import { Location } from '@angular/common' ; import { Injectable } from '@angular/core' ; import { NavigationBehaviorOptions , Router } from '@angular/router' ; import { NavController } from '@ionic/angular' ; import { Identifiable } from '../../models/identifiable' ; interface State { [ key ] : any ; } @ Injectable ( { providedIn : 'root' } ) export class NavigationService { private state : State = { } ; constructor ( private readonly router , private readonly location , private readonly navCtrl ) { } public async routeWithIdentifiableObject ( router , route , object ) { return router . navigate ( [ route , object . getIdentifier ( ) ] ) ; } public route ( route ) { return this . router . navigateByUrl ( route ) ; } public async routeWithState ( route , object , options ? ) { this . state = object ; return this . router . navigateByUrl ( route , options ) ; } public back ( ) { this . location . back ( ) ; } public routeBack ( route ) { this . navCtrl . navigateBack ( route ) ; } public getState ( ) { return this . state ; } public routeToAccountsTab ( clearStack = false ) { return this . router . navigateByUrl ( '/tabs/tab-accounts' , { replaceUrl : clearStack } ) ; } public routeToScanTab ( clearStack = false ) { return this . router . navigateByUrl ( '/tabs/tab-scan' , { replaceUrl : clearStack } ) ; } public routeToSettingsTab ( clearStack = false ) { return this . router . navigateByUrl ( '/tabs/tab-settings' , { replaceUrl : clearStack } ) ; } }