Search in sources :

Example 6 with NavigationHandler

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;
}
Also used : NavigationHandler(com.vaadin.flow.router.NavigationHandler) Location(com.vaadin.flow.router.Location)

Example 7 with NavigationHandler

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);
}
Also used : ErrorNavigationEvent(com.vaadin.flow.router.ErrorNavigationEvent) AfterNavigationEvent(com.vaadin.flow.router.AfterNavigationEvent) NavigationEvent(com.vaadin.flow.router.NavigationEvent) NavigationHandler(com.vaadin.flow.router.NavigationHandler)

Example 8 with NavigationHandler

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());
}
Also used : LocationChangeEvent(com.vaadin.flow.router.legacy.LocationChangeEvent) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) Arrays(java.util.Arrays) NavigationHandler(com.vaadin.flow.router.NavigationHandler) ParentView(com.vaadin.flow.router.legacy.ViewRendererTest.ParentView) Test(org.junit.Test) AnotherTestView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView) List(java.util.List) RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) Location(com.vaadin.flow.router.Location) View(com.vaadin.flow.router.legacy.View) UI(com.vaadin.flow.component.UI) Assert(org.junit.Assert) Collections(java.util.Collections) NavigationEvent(com.vaadin.flow.router.NavigationEvent) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) NavigationTrigger(com.vaadin.flow.router.NavigationTrigger) Before(org.junit.Before) NavigationHandler(com.vaadin.flow.router.NavigationHandler) Test(org.junit.Test)

Example 9 with NavigationHandler

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);
}
Also used : RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) NavigationHandler(com.vaadin.flow.router.NavigationHandler) Location(com.vaadin.flow.router.Location)

Example 10 with NavigationHandler

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);
}
Also used : ErrorNavigationEvent(com.vaadin.flow.router.ErrorNavigationEvent) AfterNavigationEvent(com.vaadin.flow.router.AfterNavigationEvent) NavigationEvent(com.vaadin.flow.router.NavigationEvent) NavigationHandler(com.vaadin.flow.router.NavigationHandler)

Aggregations

NavigationHandler (com.vaadin.flow.router.NavigationHandler)10 Location (com.vaadin.flow.router.Location)7 NavigationEvent (com.vaadin.flow.router.NavigationEvent)5 UI (com.vaadin.flow.component.UI)3 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)3 List (java.util.List)3 Test (org.junit.Test)3 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)2 ErrorNavigationEvent (com.vaadin.flow.router.ErrorNavigationEvent)2 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)2 LocationChangeEvent (com.vaadin.flow.router.legacy.LocationChangeEvent)2 RouterTestUI (com.vaadin.flow.router.legacy.RouterTest.RouterTestUI)2 View (com.vaadin.flow.router.legacy.View)2 AnotherParentView (com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView)2 AnotherTestView (com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView)2 ParentView (com.vaadin.flow.router.legacy.ViewRendererTest.ParentView)2 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Assert (org.junit.Assert)2