I'm using leaflet to generate a route and display the route on the map. When I make another route, I want to delete the previous from the map and add the new one, but when I start to move the map, with the mouse and zoom controls I get the following error;
leaflet-routing-machine.min.js:3 Uncaught TypeError: Cannot read property 'getZoom' of null
here is my code;
if (routeControl != null){
routeControl.removeFrom(map);}
routeControl = new L.Routing.Control({
waypoints: setWaypoints,
show:false,
}).addTo(map);
thanks in advance