You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.3 KiB

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<IStateChanges> = new Subject<IStateChanges>();
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();
}
}