您好,我正在开发 GWT 示例历史管理应用程序。
这是我的 onModuleLoad 代码。
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。
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 就可以正常工作。
现在我想知道仅在模块加载时需要 History.fireCurrentHistoryState() 吗?
另外为什么在申请中不需要第二次?
History.fireCurrentHistoryState()
调用您的历史记录处理程序,而无需在浏览器历史记录堆栈中实际插入新的历史记录项,而History.newItem(token)
确实将新的历史标记插入历史堆栈中。
Note:如果您当前的令牌与新令牌相同(即重新加载同一页面),则浏览器不会将其插入历史堆栈。在这种情况下(当前令牌==新令牌)History.fireCurrentHistoryState()
具有相同的效果History.newItem(currentToken)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)