更改URL而不转换 [英] Change URL without transition

查看:147
本文介绍了更改URL而不转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于Ember路由系统的问题。



在我的Ember-App中,我有一个简单的传单全屏地图。该地图的中心和缩放级别来自URL查询参数。现在,有一个简单的方法来保持这个查询参数与地图位置同步是很好的。所以当有人移动地图时,我想将url查询参数更改为新的值。



当我使用简单的 transitionTo 时,我开始一个更改地图的循环,并更新查询参数,再次映射,等等。



所以我的第一个想法是从路由器获取位置实现,并手动更改url。但我不知道该怎么做而且,Ember这样做也是错误的。

解决方案

在我的回答中有很多downvote,在Ember中,你也可以这样做所以你不要经历过渡或重新加载数据/渲染

  Ember.run(function(){
window.history.replaceState({},'foo','/ foo');
});

或传统浏览器访问哈希:

  Ember.run(function(){
location.hash ='foo';
});


I have a question concerning the Ember routing system.

In my Ember-App, I have a simple leaflet fullscreen map. The center and zoom level of this map are coming from the URL query parameters. Now it would be nice to have a simple way to keep this query parameters in sync with the map position. So when somebody moves the map, I would like to change the url query parameters to the new values.

When I use a simple transitionTo, I start a loop of changing the map and updating the query parameters changing the map again and so forth.

So my first idea was to get the location implementation from the router and changing the url manually. But I do not know how to do that. And it also feals wrong using Ember this way.

解决方案

After many downvotes to my answer above, in Ember you could also do this so you don't go through a transition or reloading data / rendering

Ember.run(function(){ 
    window.history.replaceState( {} , 'foo', '/foo' );
});

Or for legacy browsers access the hash:

Ember.run(function(){
    location.hash = 'foo';
});

这篇关于更改URL而不转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆