Search in sources :

Example 1 with NotFoundException

use of com.vaadin.flow.router.NotFoundException in project flow by vaadin.

the class DefaultRouteResolver method resolve.

@Override
public NavigationState resolve(ResolveRequest request) {
    RouteRegistry registry = request.getRouter().getRegistry();
    PathDetails path = findPathString(registry, request.getLocation().getSegments());
    if (path == null) {
        return null;
    }
    NavigationStateBuilder builder = new NavigationStateBuilder();
    Class<? extends Component> navigationTarget;
    try {
        if (!path.segments.isEmpty()) {
            navigationTarget = getNavigationTargetWithParameter(registry, path.path, path.segments);
        } else {
            navigationTarget = getNavigationTarget(registry, path.path);
        }
        if (HasUrlParameter.class.isAssignableFrom(navigationTarget)) {
            List<String> pathParameters = getPathParameters(request.getLocation().getPath(), path.path);
            if (!ParameterDeserializer.verifyParameters(navigationTarget, pathParameters)) {
                return null;
            }
            builder.withTarget(navigationTarget, pathParameters);
        } else {
            builder.withTarget(navigationTarget);
        }
        builder.withPath(path.path);
    } catch (NotFoundException nfe) {
        String message = "Exception while navigation to path " + path;
        LoggerFactory.getLogger(this.getClass().getName()).warn(message, nfe);
        throw nfe;
    }
    return builder.build();
}
Also used : NavigationStateBuilder(com.vaadin.flow.router.NavigationStateBuilder) RouteRegistry(com.vaadin.flow.server.startup.RouteRegistry) NotFoundException(com.vaadin.flow.router.NotFoundException)

Aggregations

NavigationStateBuilder (com.vaadin.flow.router.NavigationStateBuilder)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1 RouteRegistry (com.vaadin.flow.server.startup.RouteRegistry)1