import { Router } from '@angular/router'; import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; interface IStateChanges { previousRoute: string; currentRoute: string; } @Injectable() export class RouterService { private static previousRoute: string; private static currentRoute: string; public previousPage: string; private _stateChanges: Subject = new Subject(); public selectedTab: string = ''; constructor(private _router: Router) { this.previousPage = ''; } public setSelectedTab(str: string) { this.selectedTab = str; } public getSelectedTab() { return this.selectedTab; } public navigate(route: string) { // ** // Note: replaceUrl is used in future by us to replace the urlParams based on the route // ** this._router.navigateByUrl(route, { replaceUrl: true }); } public navigateRelatively(route: string) { this._router.navigate([route], { relativeTo: this._router.routerState.root.firstChild }); } public navigateBack() { window.history.back(); } public get previousRoute() { return RouterService.previousRoute; } public get currentRoute() { return RouterService.currentRoute; } public get stateChanges() { return this._stateChanges.asObservable(); } }