import {PathLocationStrategy} from "@angular/common";
import {Injectable, OnDestroy} from "@angular/core";

@Injectable()
export class MfeScopedLocationStrategy extends PathLocationStrategy implements OnDestroy {
  private isDestroyed: boolean = false;

  replaceState(state: any, title: string, url: string, queryParams: string) {
    if (!this.isDestroyed) {
      super.replaceState(state, title, url, queryParams);
    }
  }

  pushState(state: any, title: string, url: string, queryParams: string) {
    if (!this.isDestroyed) {
      super.pushState(state, title, url, queryParams);
    }
  }

  ngOnDestroy(): void {
    this.isDestroyed = true;
  }
}