我为我的 mvp4g 项目实现了历史机制。当我遍历页面时,我可以看到 url 也发生了变化。但是在重新加载除主页以外的任何页面时,总是显示主页而不是所需的页面?
这是我的实现:
@History(type = HistoryConverterType.SIMPLE)
public class CustomHistoryConverter implements HistoryConverter<AppEventBus> {
private CustomEventBus eventBus;
@Override
public void convertFromToken(String historyName, String param, CustomEventBus eventBus) {
this.eventBus = eventBus;
eventBus.dispatch(historyName, param);
}
public String convertToToken(String eventName, String name) {
return name;
}
public String convertToToken(String eventName) {
return eventName;
}
public String convertToToken(String eventName, String name, String type) {
return name;
}
public boolean isCrawlable() {
return false;
}
}
以及事件总线相关代码:
@Events(startPresenter=PageOnePresenter.class,historyOnStart=true)
public interface CustomEventBus extends EventBusWithLookup {
@Start
@Event(handlers = PageOnePresenter.class)
void start();
@InitHistory
@Event(handlers = PageOnePresenter.class)
void init();
@Event(handlers = PageTwoPresenter.class, name = "page2", historyConverter = CustomHistoryConverter.class)
void getPageTwo();
@Event(handlers = PageThreePresenter.class, name = "page3", historyConverter=CustomHistoryConverter.class)
void getPageThree();
@Event(handlers=PageOnePresenter.class, name = "page1", historyConverter=CustomHistoryConverter.class)
void getPageOne();
@Event(handlers=PageOnePresenter.class)
void setPageTwo(HistoryPageTwoView view);
@Event(handlers=PageOnePresenter.class)
void setPageThree(HistoryPageThreeView view);
}
最佳答案
HistoryConverter 需要改进。
事实上,该事件没有参数,您应该返回一个空字符串。更新 HistoryConverter,使其看起来像这样:
@History(type = HistoryConverterType.SIMPLE)
public class CustomHistoryConverter implements HistoryConverter<AppEventBus> {
private CustomEventBus eventBus;
@Override
public void convertFromToken(String historyName, String param, CustomEventBus eventBus) {
this.eventBus = eventBus;
// TODO handle the param in cases where you have more than one parameter
eventBus.dispatch(historyName, param);
}
public String convertToToken(String eventName, String name) {
return name;
}
public String convertToToken(String eventName) {
return "";
}
public String convertToToken(String eventName, String name, String type) {
return name - "-!-" type;
}
public boolean isCrawlable() {
return false;
}
}
希望有帮助。
关于java - 重新加载页面时,mvp4g 历史记录机制失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42572804/