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