简体   繁体   English

如何在不去往/开始活动的情况下更改浏览器历史记录(gwt)

[英]how to change browser history without going to place/ starting activity (gwt)

in my app i have a relative complex activity/place. 在我的应用程序中,我有一个相对复杂的活动/地方。 Resolving the state (from history token to model) on start of activity causes some server interactions. 在活动开始时解析状态(从历史令牌到模型)会导致一些服务器交互。 On user interactions the activity only updates the necessary parts of the model and therefore safes some server interactions - the activity/model has an inner state. 在用户交互中,活动仅更新模型的必要部分,因此保护一些服务器交互 - 活动/模型具有内部状态。

Is there a way to reflect the state in browser history without (re)starting the activity? 有没有办法在没有(重新)启动活动的情况下反映浏览器历史记录中的状态? ( History.newItem(token) also causes start of activity) History.newItem(token)也会导致活动开始)

UPDATE Chris' solution "nearly" works but another problem rose: in my ui i have a reset-button (a link to the place with empty token). 更新克里斯的解决方案“几乎”有效,但另一个问题上升了:在我的ui中我有一个重置按钮(指向空标记的地方的链接)。 If i click around the ui the token is updated fine but now the reset button doesn't work. 如果我点击ui周围令牌已更新,但现在重置按钮不起作用。 gwt thinks it is in the same place and so it ignores the reset click. gwt认为它在同一个地方,所以它忽略了重置点击。 Before this the problem was nearly the same: the token and place didn't change and so the reset button didn't work either. 在此之前问题几乎相同:令牌和地点没有改变,因此重置按钮也不起作用。 GWT logs this as "Asked to return to the same place" GWT记录为“被要求返回同一个地方”

So is there a way to let gwt restart the activity regardless of place equivalence? 那么有没有办法让gwt重新启动活动而不管地点等价?

Go to a new place, but have your ActivityMapper return the same activity instance. 转到新位置,但让ActivityMapper返回相同的活动实例。 That way, the activity is not restarted. 这样,活动就不会重新启动。
You have to find a mean of updating the activity when the place changes from some other mean though (eg browser history). 当地点从其他方面改变时,你必须找到更新活动的方法(例如浏览器历史记录)。 See GWT MVP updating Activity state on Place change for instance. 例如,请参阅GWT MVP更新Place更改的活动状态

There is a semi-solution, and although I don't want to recommend it , I'd like to add it here - just to warn against the drawbacks of this solution: 有一个半解决方案,虽然我不想推荐它 ,但我想在这里添加它 - 只是为了警告这个解决方案的缺点:

You could add tokens to the History without firing an event by calling History.newItem(token, false) . 您可以通过调用History.newItem(token, false)将标记添加到历史记录而不触发事件。

This is a semi-solution, because: 这是一个半解决方案,因为:

  • It works correctly (as long as you build your tokens correctly). 它工作正常(只要你正确构建你的令牌)。
  • A part of the performance problem is also solved: The activity won't be re-started when adding the token to the history. 还解决了性能问题的一部分:将令牌添加到历史记录时,不会重新启动活动。
  • However, if the user goes back and forward through the history, the performance problem would still be there (because then, the events will be fired again). 但是,如果用户在历史记录中前后移动,则性能问题仍然存在(因为那时,事件将再次触发)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GWT默认会自动在浏览器历史记录中放置? - GWT default place automatically in browser history? GWT MVP更新地方变更的活动状态 - GWT MVP updating Activity state on Place change GWT MVP更新历史记录而不更改活动 - GWT MVP Update the History-Token without changing the Activity 通过GWT场所API,如何在不重新加载页面的情况下更改URL / PLACE / Place-Token? - VIA the GWT places API how do you change the URL/PLACE/Place-Token without reloading the page? 在没有浏览器历史记录更改的情况下寻找有关GWT / MVP操作的输入 - Looking for input on GWT / MVP action w/o browser history change GWT活动:如何使用活动,场所,事件总线和uibinder - GWT Activity : How to use an activity, place, eventbus and uibinder 如何将GWT Place URL从默认的“:”更改为“/”? - How to change GWT Place URL from the default “:” to “/”? 如何使用gwt历史查找浏览器后退按钮单击 - How to find out browser back button click using gwt history 如何通过GWT中的历史来确定我是“前进”还是“后退”? - How do I determine whether I am going “forward” or “backward” through my History in GWT? Intellij/GWT 在没有排列的情况下启动 gwt 应用程序 - Intellij/GWT Starting a gwt application without permutations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM