Keep State In Routing #Angular

PHOTO EMBED

Sun May 12 2024 12:05:20 GMT+0000 (Coordinated Universal Time)

Saved by @Samarmhamed78

#AppComponent
ngOnInit() {
    this.translateService.setDefaultLang('ar');
    let historyState = JSON.parse(localStorage.getItem('historyState')!) as object;
    if (historyState) {
      history.pushState(historyState, "")
      localStorage.removeItem('historyState')
    }
  }
  @HostListener('window:beforeunload') getHistoryState() {
    if (history.state)
      localStorage.setItem('historyState', JSON.stringify(history.state));
  }
content_copyCOPY