Class RouteHierarchy

java.lang.Object
com.vaadin.flow.router.RouteHierarchy

public final class RouteHierarchy extends Object
Walks the route hierarchy starting from a given @Route annotated class.

At each step, the walker first consults @RouteParent: if the annotation is present, its target is itself @Route-annotated and has not yet been visited, that target becomes the parent. Otherwise the walker falls back to URL-prefix walking: it takes the current class's route template via RouteConfiguration.getTemplate(Class), strips the last /-separated segment, and looks up the resulting path in the supplied RouteConfiguration. Traversal terminates when no parent can be resolved, when a candidate would form a cycle, or when the current template has no further segments to strip.

Cycles in the hierarchy are detected via a visited set and truncated rather than reported as errors. The resulting chain is therefore always finite and free of duplicates.

See Also:
  • Method Details

    • resolveAncestors

      public static List<Class<? extends Component>> resolveAncestors(Class<? extends Component> routeClass, RouteConfiguration routeConfiguration)
      Returns the chain of route classes from the conceptual root down to and including routeClass.

      The returned list is root-first: the root ancestor comes first and routeClass is always the last element. When routeClass is not annotated with @Route, an empty list is returned. When routeClass is a @Route view but no parent can be resolved, the returned list contains only routeClass itself.

      The walk consults @RouteParent first at each step and falls back to URL-prefix walking via RouteConfiguration.getTemplate(Class) and RouteConfiguration.getRoute(String). Cycles are truncated.

      Parameters:
      routeClass - the route class to start from, not null
      routeConfiguration - the route configuration used to resolve templates and ancestor routes, not null
      Returns:
      root-first list of ancestor route classes inclusive of routeClass, or an empty list when routeClass is not annotated with @Route
      See Also:
    • resolveParent

      public static Optional<Class<? extends Component>> resolveParent(Class<? extends Component> routeClass, RouteConfiguration routeConfiguration)
      Returns the immediate parent of routeClass, or an empty Optional when no parent can be resolved.

      This is equivalent to taking the second-to-last entry of resolveAncestors(Class, RouteConfiguration) for chains of length two or more, and empty otherwise. @RouteParent is consulted first; URL-prefix walking is the fallback.

      Parameters:
      routeClass - the route class to find the parent of, not null
      routeConfiguration - the route configuration used to resolve templates and ancestor routes, not null
      Returns:
      an Optional describing the parent route class, or Optional.empty() when routeClass has no @Route annotation or no parent can be resolved
      See Also: