简体   繁体   English

如何在不重新加载页面的情况下手动设置“ this.props.history.location.pathname”的值?

[英]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: 每当位置改变你latlong然后做的东西,如:

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.

相关问题 保留初始 props.history.location.pathname 并从那里导航 - Preserve the initial props.history.location.pathname and navigate from there 刷新视图页面,而无需手动重新加载页面 - Refresh view page without reloading the page manually Reactjs,如何将props.location.pathname与字符串进行比较? - Reactjs, How to compare props.location.pathname to a string? 如何重新加载Next.js页面初始道具而不重新加载整个页面 - How to reload Next.js page initial props without reloading the whole page 如何使用PHP访问由History.PushState创建的查询字符串变量而不使用ajax并且不重新加载页面 - How to use PHP to access query string variables created by History.PushState without ajax and without reloading the page React 中动态 URL 的 this.props.location.pathname - this.props.location.pathname for dynamic URLs in React Angular 7 location.back 无需重新加载页面 - Angular 7 location.back without reloading the page 如何在不重新加载页面的情况下以角度 2 设置或删除当前路线中的 queryParams - How to set or remove queryParams in current route in angular 2 without reloading page 避免手动重新加载页面? - Avoiding manually reloading the page? 重新加载页面后如何在AJAX成功函数中设置值? - How to set a value in AJAX success function after reloading the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM