我已经为我的mvp4g项目实现了历史记录机制。当我遍历页面时,我可以看到网址也发生了变化。但是在重新加载主页以外的任何页面时,总是会显示主页而不是所需的页面?
这是我的实施:
@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);
}
答案 0 :(得分:1)
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;
}
}
希望有所帮助。