Reputation: 1674
I'm working on small extension to add my map based project. That extension should show lat, long of place on URL like this! Whenever location changes by user.
Problem is I could not change pathname of this.props.history.location when user changes location for second time
this.map.on("moveend", e => {
if (!this.props.history.location.pathname.substr(4)) {
console.log(this.props.history.location, "no change");
this.props.history.replace(
[
"map",
e.target._zoom,
e.target._lastCenter.lat,
e.target._lastCenter.lng
].join("/")
);
} else {
console.log(this.props.history.location, "change");
}
});
Upvotes: 0
Views: 1268
Reputation: 511
First of All keep URL in some constant:
const URL = http://mlevans.com/leaflet-hash/map.html#12/lat/long
whenever location changes you get lat
and long
then do stuff like:
const mapURL = URL.replace(lat, long, this.history.match.params.lat , this.history.match.params.long);
this.history.push(mapURL);
In react router you should have component mapped to http://mlevans.com/leaflet-hash/map.html#12/:lat/:long
Upvotes: 1