I have the following code to detect the back button press using angular 6.

import { Location } from '@angular/common';export class ProductsComponent 
implements OnInit {
constructor( private location: Location){
  this.handleBackButtonPress();}
  handleBackButtonPress() {
    this.subscribed = true;
    this.location.subscribe(redirect => {
     if (redirect.pop === true) {
      alert('this is a backbutton click');
     }
    });
  }}


This is working and we got alert on back button press. The problem is If we 
visit the same page more than once it will trigger the alert with the 
number of time we visited the route with the same component.

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to