Interface RouteParentResolver

All Superinterfaces:
Serializable
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface RouteParentResolver extends Serializable
Resolves the logical parent of a route dynamically without requiring an instance of either the route or its parent.

This is the dynamic counterpart of a static RouteParent.value(). The logical parent it returns is used to build navigation hierarchies, such as breadcrumb trails, where the whole chain of ancestor routes needs to be known without instantiating any of them. It mirrors PageTitleGenerator: the parent is resolved purely from the navigation target class and its RouteParameters.

A resolver is referenced from a route through RouteParent.resolver():

 @Route("orgs/:orgId/projects/:projectId")
 @RouteParent(resolver = OrgParentResolver.class)
 public class ProjectView extends Div {
     // ...
 }

 public class OrgParentResolver implements RouteParentResolver {
     @Override
     public Optional<RouteReference> resolveParent(
             RouteParentContext context) {
         // carry over only the parameters the parent route needs
         RouteParameters parentParameters = new RouteParameters("orgId",
                 context.routeParameters().get("orgId").orElseThrow());
         return Optional
                 .of(new RouteReference(OrgView.class, parentParameters));
     }
 }
 
Returning an empty Optional marks the top of the hierarchy.

Implementations must be stateless and are expected to be cheap to create: they are instantiated through the application Instantiator (so dependency injection is available) every time a parent is resolved, never the route itself.

Since:
25.2
Author:
Vaadin Ltd
  • Method Details

    • resolveParent

      Optional<RouteReference> resolveParent(RouteParentContext context)
      Resolves the logical parent of the route described by the given context.

      The returned reference carries both the parent navigation target and the RouteParameters it should be resolved with. The resolver is responsible for mapping the child route parameters to the subset the parent route expects.

      Parameters:
      context - the context describing the route whose parent is resolved and its route parameters, not null
      Returns:
      the logical parent reference, or an empty Optional if the route has no logical parent (it is a hierarchy root)