我已经为我的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);
}发布于 2017-03-03 17:53:03
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;
}
}希望这能有所帮助。
https://stackoverflow.com/questions/42572804
复制相似问题