diff --git a/src/components/geolocate-control.js b/src/components/geolocate-control.js index 4ffd59ad..ab90f75b 100644 --- a/src/components/geolocate-control.js +++ b/src/components/geolocate-control.js @@ -110,10 +110,12 @@ export default class GeolocateControl extends BaseControl< componentWillUnmount() { // re-implement MapboxGeolocateControl's _onRemove // clear the geolocation watch if exists - const geolocationWatchID = this._mapboxGeolocateControl._geolocationWatchID; - if (geolocationWatchID !== undefined) { - window.navigator.geolocation.clearWatch(geolocationWatchID); - this._mapboxGeolocateControl._geolocationWatchID = undefined; + if (this._mapboxGeolocateControl) { + const geolocationWatchID = this._mapboxGeolocateControl._geolocationWatchID; + if (geolocationWatchID !== undefined) { + window.navigator.geolocation.clearWatch(geolocationWatchID); + this._mapboxGeolocateControl._geolocationWatchID = undefined; + } } }