GWT 历史记录中需要 History.fireCurrentHistoryState() 什么? [英] What is need History.fireCurrentHistoryState() in GWT History?

查看:15
本文介绍了GWT 历史记录中需要 History.fireCurrentHistoryState() 什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在开发 GWT 示例历史记录管理应用程序.这是我的 onModuleLoad 代码.

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();
}

在这里我解雇了 History.fireCurrentHistoryState();以触​​发当前的历史状态.现在,在我的 firstPanel 类中,有一个名为 Second Panel 的按钮,在该按钮上触发了历史标记 second_page.

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);
}

但是这里不需要触发 History.fireCurrentHistoryState() ;再次.简单的 history.newItem 工作正常.

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

现在我想知道 History.fireCurrentHistoryState() 在模块加载时需要什么?还有为什么在应用程序中不需要第二次.?

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

推荐答案

History.fireCurrentHistoryState() 调用您的历史处理程序,而无需在浏览器历史堆栈中实际插入新的历史项目,而 History.newItem(token) 确实将新的历史令牌插入到历史堆栈中.

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.

注意:如果您当前的令牌与新令牌相同(即重新加载同一页面),则浏览器不会将其插入到历史堆栈中.在这种情况下(当前令牌 == 新令牌)History.fireCurrentHistoryState()History.newItem(currentToken) 具有相同的效果.

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

这篇关于GWT 历史记录中需要 History.fireCurrentHistoryState() 什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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