import { Injectable } from '@angular/core'; import { CanDeactivate, Router} from '@angular/router'; import {Observable} from 'rxjs'; import {properties} from "../../../../environments/environment"; @Injectable({ providedIn: 'root' }) // do not forget to register this class as a provider export class PreviousRouteRecorder implements CanDeactivate { constructor(private router: Router) { } canDeactivate(component: any): Observable | boolean { if (typeof localStorage !== 'undefined') { // console.log("In PreviousRouteRecorder : "+properties.baseLink + this.router.url ); localStorage.setItem('previousRoute', properties.baseLink + this.router.url); } return true; } }