[英]How to set value of “ this.props.history.location.pathname ” manually without reloading page?
I'm working on small extension to add my map based project. 我正在做小扩展,以添加基于地图的项目。 That extension should show lat, long of place on URL like this !
该扩展名应该在URL上这样显示很长的位置! 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.props.history.location的路径名
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");
}
});
First of All keep URL in some constant: 首先,保持URL不变:
const URL = http://mlevans.com/leaflet-hash/map.html#12/lat/long
whenever location changes you get lat
and long
then do stuff like: 每当位置改变你
lat
和long
然后做的东西,如:
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
在React Router中,您应该将组件映射到
http://mlevans.com/leaflet-hash/map.html#12/:lat/:long
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.