1

For example I am from the current url http://localhost:4200/#/transactions/overview/5?tab=2 and then I navigated to http://localhost:4200/#/deals/detail/

When I refresh the deals/detail page I want to go back to the previous url which is for example http://localhost:4200/#/transactions/overview/5?tab=2.

How do we address this is angular ? Thank you for help and ideas.

#code for navigating to deals/detail page

 editDeal(deal:any){
        let dealType = '';
        const state = { 
          data: {
            transaction: this.transaction,
          },      
        }
        this.gotoDealDetails(state);    
      }
    
      gotoDealDetails(state:any){
        this.route.navigateByUrl(`deals/detail/`, {state: state});
      }

#detail details page component

export class DealDetailsComponent implements OnInit {


      dealDetails = null;
      leaseDetails = null;
      currentRentSchedule = [];
      isInEditMode = false;
      fiscalYear = null;
      pmrType = null;
      partnerType: any;
    
      constructor(
        private _route: Router,    
        private _dealService: DealService,
        private dialog: MatDialog,
        private _notificationService: NotificationService) {
        this.urlData = this._route.getCurrentNavigation().extras.state.data
      }
    
      ngOnInit(): void {    
    
      }
    
      ngAfterViewInit() {
    
      }
    
    }
  • You should be saving the last URL in local storage and then you can access it first thing in your detail component. Some logic can be added to get the URL from local storage and then navigate back to it. Check: https://stackoverflow.com/questions/41038970/how-to-determine-previous-page-url-in-angular – Adithya Sreyaj Nov 30 '21 at 05:36

1 Answers1

2

When you refresh the page, get any event to be called on refresh page and in that event you can call back() method as below in your component (here taken name as AnyComponent) in which you want to perform refresh :

component.ts file example

import { Location } from '@angular/common'

    @Component({...})
    export class AnyComponent {
      constructor(private location: Location) {}

      back(): void {
        this.location.back()
      }
    }

Refer this link for more detail: https://nils-mehlhorn.de/posts/angular-navigate-back-previous-page

R. Richards
  • 24,603
  • 10
  • 64
  • 64
sda87
  • 372
  • 3
  • 10