Search in sources :

Example 6 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class BeforeEvent method rerouteTo.

/**
 * Reroutes the navigation to the given navigation state.
 *
 * @param targetState
 *            the target navigation state of the rerouting, not {@code null}
 */
public void rerouteTo(NavigationState targetState) {
    Objects.requireNonNull(targetState, "targetState cannot be null");
    rerouteTo(new NavigationStateRenderer(targetState), targetState);
}
Also used : NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer)

Example 7 with NavigationStateRenderer

use of com.vaadin.flow.router.internal.NavigationStateRenderer in project flow by vaadin.

the class Router method handleNavigation.

private int handleNavigation(UI ui, Location location, NavigationTrigger trigger) {
    NavigationState newState = getRouteResolver().resolve(new ResolveRequest(this, location));
    if (newState != null) {
        NavigationEvent navigationEvent = new NavigationEvent(this, location, ui, trigger);
        NavigationHandler handler = new NavigationStateRenderer(newState);
        return handler.handle(navigationEvent);
    } else if (!location.getPath().isEmpty()) {
        Location slashToggledLocation = location.toggleTrailingSlash();
        NavigationState slashToggledState = getRouteResolver().resolve(new ResolveRequest(this, slashToggledLocation));
        if (slashToggledState != null) {
            NavigationEvent navigationEvent = new NavigationEvent(this, slashToggledLocation, ui, trigger);
            NavigationHandler handler = new InternalRedirectHandler(slashToggledLocation);
            return handler.handle(navigationEvent);
        }
    }
    throw new NotFoundException("Couldn't find route for '" + location.getPath() + "'");
}
Also used : InternalRedirectHandler(com.vaadin.flow.router.internal.InternalRedirectHandler) ResolveRequest(com.vaadin.flow.router.internal.ResolveRequest) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer)

Aggregations

NavigationStateRenderer (com.vaadin.flow.router.internal.NavigationStateRenderer)7 Test (org.junit.Test)4 RouterLayout (com.vaadin.flow.router.RouterLayout)3 Component (com.vaadin.flow.component.Component)1 Text (com.vaadin.flow.component.Text)1 Location (com.vaadin.flow.router.Location)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 Router (com.vaadin.flow.router.Router)1 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)1 InternalRedirectHandler (com.vaadin.flow.router.internal.InternalRedirectHandler)1 ResolveRequest (com.vaadin.flow.router.internal.ResolveRequest)1 MockInstantiator (com.vaadin.flow.server.MockInstantiator)1 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)1 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)1 MockUI (com.vaadin.tests.util.MockUI)1