import { Injectable } from '@angular/core'; import { CookieService } from './cookie.service'; @Injectable({ providedIn: 'root' }) export class SessionService { private readonly redirectStateKey = '_redirectState'; constructor ( private cookieService: CookieService ) {} setRedirectToState (stateName: string, toParams: any) { const state = { stateName, toParams }; this.cookieService.putObject(this.redirectStateKey, (state as any)); } getRedirectToState () { const redirectState = this.cookieService.getObject(this.redirectStateKey); this.cookieService.delete(this.redirectStateKey); return redirectState; } clearRedirectToState () { this.cookieService.delete(this.redirectStateKey); } }