Q:

Location.subscribe() is leaking

I use Location.subscribe() to detect "back" button.
https://angular.io/docs/ts/latest/api/common/index/Location-class.html
export class PathLocationComponent {
  location: Location;
  constructor(location: Location) { 
     location.subscribe(val => console.log(val))//output popstate
  }
}

However, The number of logs increases when I repeat pushing "back"&"forward" button.
I think Locaion.subscribe() is leaking.
but I don't know how to release it because Location class doesn't have unsubscribe().
How to release Location.subscribe() or prevent leak?

I thought of using PlatformLocation.onPopState().
https://angular.io/docs/ts/latest/api/common/index/PlatformLocation-class.html
But,documentation says below
This class should not be used directly by an application developer. Instead, use Location.

A:

You can try this: 

import {Subscription} from 'rxjs/Subscription';

export class PathLocationComponent implements OnDestroy {
location: Location;
private subscription: Subscription;

      constructor(location: Location) {
        this.subscription = location.subscribe(val => console.log(val))//output popstate
      }

     ngOnDestroy(): void {
        this.subscription.unsubscribe();
     }
}

