use of com.vaadin.flow.router.NavigationHandler in project flow by vaadin.
the class RouterConfiguration method resolveRoute.
private static NavigationHandler resolveRoute(RouteTreeNode node, Location location) {
String segment = location.getFirstSegment();
Optional<Location> maybeSubLocation = location.getSubLocation();
NavigationHandler handler = null;
if (maybeSubLocation.isPresent()) {
// Try to use a child node if there are more path segments
RouteTreeNode childNode = node.resolveChild(segment);
if (childNode != null) {
handler = resolveRoute(childNode, maybeSubLocation.get());
}
} else {
// Find an actual handler if this is the last path segment
handler = node.resolveRoute(segment);
}
if (handler == null) {
// Use a wildcard handler if we haven't found anything else
handler = node.getWildcardHandler();
}
return handler;
}
use of com.vaadin.flow.router.NavigationHandler in project flow by vaadin.
the class AbstractNavigationStateRenderer method forward.
private int forward(NavigationEvent event, BeforeEvent beforeNavigation) {
NavigationHandler handler = beforeNavigation.getForwardTarget();
NavigationEvent newNavigationEvent = getNavigationEvent(event, beforeNavigation);
newNavigationEvent.getUI().getPage().getHistory().replaceState(null, newNavigationEvent.getLocation());
return handler.handle(newNavigationEvent);
}
use of com.vaadin.flow.router.NavigationHandler in project flow by vaadin.
the class LocationChangeEventTest method explicitRerouteTarget.
@Test
public void explicitRerouteTarget() {
NavigationHandler handler = e -> 200;
event.rerouteTo(handler);
Assert.assertTrue(event.getRerouteTarget().isPresent());
Assert.assertSame(handler, event.getRerouteTarget().get());
}
use of com.vaadin.flow.router.NavigationHandler in project flow by vaadin.
the class RouterConfigurationTest method assertRoutePriority.
private static void assertRoutePriority(String location, String strongerRoute, String weakerRoute) {
// First verify that the test makes sense
assertMatches(location, strongerRoute);
assertMatches(location, weakerRoute);
NavigationHandler weakerHandler = createNoopHandler();
NavigationHandler strongerHandler = createNoopHandler();
RouterConfiguration configuration = createConfiguration();
configuration.setRoute(strongerRoute, strongerHandler);
configuration.setRoute(weakerRoute, weakerHandler);
Optional<NavigationHandler> handler = configuration.resolveRoute(new Location(location));
Assert.assertSame(handler.get(), strongerHandler);
// Do the same again with setRoute run in the opposite order
configuration = createConfiguration();
configuration.setRoute(weakerRoute, weakerHandler);
configuration.setRoute(strongerRoute, strongerHandler);
handler = configuration.resolveRoute(new Location(location));
Assert.assertSame(handler.get(), strongerHandler);
}
use of com.vaadin.flow.router.NavigationHandler in project flow by vaadin.
the class AbstractNavigationStateRenderer method reroute.
private int reroute(NavigationEvent event, BeforeEvent beforeNavigation) {
NavigationHandler handler = beforeNavigation.getRerouteTarget();
NavigationEvent newNavigationEvent = getNavigationEvent(event, beforeNavigation);
return handler.handle(newNavigationEvent);
}
Aggregations