简体   繁体   中英

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)

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). If i click around the ui the token is updated fine but now the reset button doesn't work. gwt thinks it is in the same place and so it ignores the reset click. 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"

So is there a way to let gwt restart the activity regardless of place equivalence?

Go to a new place, but have your ActivityMapper return the same activity instance. 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.

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) .

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM