gwtgwt-history

GWT History: historical token


The GWT History: com.google.gwt.user.client.History has a back() method which takes you to previous history token. But is there a way to get value of previous history token? Or even 2 steps previous history token?

I checked the back() method implementation for some quick leads, but that's all JS native stuff!


Solution

  • Using the History class? No. Javascript doesn't expose this information for security reasons. You shouldn't be able to spy on a user's browser history. That said, you could employ history sniffing tricks and do it, but those are all hacks of one form or another and, to my knowledge, are not very accurate.

    Your best bet would be to keep track of the history state manually. Maintain a stack of visited states and with every token change "push" and with the back button "pop". Then you can see where you were previously and even further.

    If you are going beyond just changing tokens and are changing pages within your site/application, consider sticking that stack of pages into LocalStorage. With this approach, you could even keep track of the history between refreshes and visits.