问题
So I'm doing something like this:
public class SecureActivity extends AbstractActivity {
public void start(AcceptsOneWidget container, EventBus eventBus) {
if (!_app.isUserLoggedIn()) {
_app.goTo(new LoginPlace(_app.getCurrentPlaceToken()))
} else {
// do cool secure stuff
}
}
}
But the behavior that I'm seeing is that my browser's history is for original url (from the original request), then the login:redirectPlace, and then original url again.
It seems like I need to do my redirection after the start() method has completed. Is there a proper way to delay/delegate that goTo to happen outside of the start method?
Thanks.
回答1:
That should be enough:
Scheduler.get().scheduleFinally(new ScheduledCommand() {
@Override
public void execute() {
_app.goTo(new LoginPlace(_app.getCurrentPlaceToken());
}
}
来源:https://stackoverflow.com/questions/8003229/gwt-how-do-i-go-to-a-new-place-from-within-the-activity-start-method