use of com.vaadin.flow.component.page.History in project flow by vaadin.
the class NavigationRpcHandler method handle.
@Override
public Optional<Runnable> handle(UI ui, JsonObject invocationJson) {
History history = ui.getPage().getHistory();
HistoryStateChangeHandler historyStateChangeHandler = history.getHistoryStateChangeHandler();
if (historyStateChangeHandler != null) {
JsonValue state = invocationJson.get(JsonConstants.RPC_NAVIGATION_STATE);
String location = invocationJson.getString(JsonConstants.RPC_NAVIGATION_LOCATION);
boolean triggeredByLink = invocationJson.hasKey(JsonConstants.RPC_NAVIGATION_ROUTERLINK);
NavigationTrigger trigger = triggeredByLink ? NavigationTrigger.ROUTER_LINK : NavigationTrigger.HISTORY;
HistoryStateChangeEvent event = new HistoryStateChangeEvent(history, state, new Location(location), trigger);
historyStateChangeHandler.onHistoryStateChange(event);
}
return Optional.empty();
}
use of com.vaadin.flow.component.page.History in project flow by vaadin.
the class UITest method locationAfterClientNavigation.
@Test
public void locationAfterClientNavigation() {
UI ui = createAndInitTestUI("");
History history = ui.getPage().getHistory();
history.getHistoryStateChangeHandler().onHistoryStateChange(new HistoryStateChangeEvent(history, null, new Location("foo/bar"), NavigationTrigger.HISTORY));
assertEquals("foo/bar", ui.getInternals().getActiveViewLocation().getPath());
}
Aggregations