내가 취한 접근법은 제안 된대로 코드에 기록 토큰을 저장하는 것이 었습니다. PlaceController를 확장하고 EventBus에서 장소 변경 사항을 추적하는 데 사용했습니다. 이제는 어디서나 PlaceController를 사용하고 대신 PlaceControllerExt를 사용합니다.이 메서드는 좋은 previous() 메서드를 사용하여 나를 원래 위치로 되돌려 놓습니다. 그러나 앞으로 탐색하고 결코 응용 프로그램을 벗어나지 않습니다.
public class PlaceControllerExt extends PlaceController {
private final Place defaultPlace;
private Place previousPlace;
private Place currentPlace;
public PlaceControllerExt(EventBus eventBus, Place defaultPlace) {
super(eventBus);
this.defaultPlace = defaultPlace;
eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {
public void onPlaceChange(PlaceChangeEvent event) {
previousPlace = currentPlace;
currentPlace = event.getNewPlace();
}
});
}
/**
* Navigate back to the previous Place. If there is no previous place then
* goto to default place. If there isn't one of these then it'll go back to
* the default place as configured when the PlaceHistoryHandler was
* registered. This is better than using History#back() as that can have the
* undesired effect of leaving the web app.
*/
public void previous() {
if (previousPlace != null) {
goTo(previousPlace);
} else {
goTo(defaultPlace);
}
}
}