jxycms
9/26/2018 - 3:30 AM

router event application

import { Injectable } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';

@Injectable()
export class PreviousRouteService {

  private previousUrl: string;
  private currentUrl: string;

  constructor(private router: Router) {
    this.currentUrl = this.router.url;
    router.events.subscribe(event => {
      if (event instanceof NavigationEnd) {        
        this.previousUrl = this.currentUrl;
        this.currentUrl = event.url;
      };
    });
  }

  public getPreviousUrl() {
    return this.previousUrl;
  }    
}
this.router.events.subscribe(event => {
    if(!this.commonService.readCookie("CartId")){
        window.location.reload();
    }
    if (event instanceof NavigationStart) {
        if(!event.url.includes("home")){
            this.tourStart = false;
            this.commonService.monitorStepChange("");
        }
    }
});