What is need History.fireCurrentHistoryState() in GWT History?

不羁的心 提交于 2019-12-01 06:54:48

问题


Hello I am working on a GWT sample history management application. Here is my onModuleLoad Code.

public void onModuleLoad() {
    ContentPanel panel = ContentPanel.getInstance();
    if(History.getToken()!=null && History.getToken().length()==0)
    {
        History.newItem("first_page");
    }
    History.addValueChangeHandler(new HistoryHandler());
    RootPanel.get().add(panel);
    History.fireCurrentHistoryState();
}

In this I fired History.fireCurrentHistoryState(); to fire current state of history. Now In my firstPanel class ther is button named Second Panel on which history token second_page is fired.

public FirstPanel() {
    VerticalPanel panel = new VerticalPanel();
    Button button2 = new Button("Second Panel");
    button2.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            History.newItem("second_page");
        }
    });
    panel.add(button2);
    initWidget(panel);
}

But here no need to fire History.fireCurrentHistoryState() ; again. simply histtory.newItem works fine.

Now I want to know that what the need of History.fireCurrentHistoryState() at module load time only? Also why it is not required second time in the application.?


回答1:


History.fireCurrentHistoryState() invokes your history handlers without actually inserting new history item in browser history stack, while History.newItem(token) does insert new history token into history stack.

Note: if your current token is the same as new token (i.e. same page is reloaded), then browsers do not insert this into history stack. In this case (current token == new token) History.fireCurrentHistoryState() has the same effect as History.newItem(currentToken).



来源:https://stackoverflow.com/questions/6925228/what-is-need-history-firecurrenthistorystate-in-gwt-history

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!