Class RouteUtil

java.lang.Object
com.vaadin.flow.router.internal.RouteUtil

public class RouteUtil extends Object
Utility class with methods for route handling.

For internal use only. May be renamed or removed in a future release.

Since:
1.3
  • Field Details

  • Constructor Details

    • RouteUtil

      protected RouteUtil()
  • Method Details

    • getParentLayouts

      public static List<Class<? extends RouterLayout>> getParentLayouts(VaadinContext context, Class<?> component, String path)
      Get parent layouts for navigation target according to the Route or RouteAlias annotation.
      Parameters:
      context - a Vaadin context
      component - navigation target to get parents for
      path - path used to get navigation target so we know which annotation to handle
      Returns:
      parent layouts for target
      Since:
      9.0
    • getParentLayouts

      public static List<Class<? extends RouterLayout>> getParentLayouts(RouteRegistry handledRegistry, Class<?> component, String path)
      Get parent layouts for navigation target according to the Route or RouteAlias annotation or automatically link RouterLayout annotated with the Layout annotation matching route path.
      Parameters:
      handledRegistry - current routeRegistry
      component - navigation target to get parents for
      path - path used to get navigation target so we know which annotation to handle
      Returns:
      parent layouts for target
      Since:
      24.5
    • getRoutePath

      public static String getRoutePath(VaadinContext context, Class<?> component)
      Get the actual route path including all parent layout RoutePrefix.
      Parameters:
      context - a Vaadin context
      component - navigation target component to get route path for
      Returns:
      actual path for given route target
      Since:
      9.0
    • getRouteAliasPath

      public static String getRouteAliasPath(Class<?> component, RouteAlias alias)
      Get the actual route path including all parent layout RoutePrefix.
      Parameters:
      component - navigation target component to get route path for
      alias - route alias annotation to check
      Returns:
      actual path for given route alias target
    • collectRouteParentLayouts

      public static List<Class<? extends RouterLayout>> collectRouteParentLayouts(Class<? extends RouterLayout> layout)
      Collects all parent layouts for a given route layout class.
      Parameters:
      layout - the layout class for which the parent layouts are collected.
      Returns:
      a list of all parent layout classes starting from the given layout and including all ancestors in the hierarchy.
      Since:
      24.5
    • getParentLayoutsForNonRouteTarget

      public static List<Class<? extends RouterLayout>> getParentLayoutsForNonRouteTarget(Class<?> navigationTarget)
      Collect possible route parent layouts for a navigation target that is not annotated with Route nor RouteAlias, but may still contain ParentLayout. Mainly error navigation targets.
      Parameters:
      navigationTarget - route to check parent layouts for
      Returns:
      list of parent layouts
    • getTopParentLayout

      public static Class<? extends RouterLayout> getTopParentLayout(VaadinContext context, Class<?> component, String path)
      Get the top most parent layout for navigation target according to the Route or RouteAlias annotation. Also handles non route targets with ParentLayout.
      Parameters:
      context - a Vaadin context
      component - navigation target to get top most parent for
      path - path used to get navigation target so we know which annotation to handle or null for error views.
      Returns:
      top parent layout for target or null if none found
      Since:
      9.0
    • resolve

      public static String resolve(VaadinContext context, Class<?> component)
      Gets the effective route path value of the annotated class.
      Parameters:
      context - a Vaadin context
      component - the component where the route points to
      Returns:
      The value of the annotation or naming convention based value if no explicit value is given.
      Since:
      9.0
    • updateRouteRegistry

      public static void updateRouteRegistry(RouteRegistry registry, Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses, Set<Class<?>> deletedClasses)
      Updates route registry as necessary when classes have been added / modified / deleted.

      Registry Update rules:

      • a route is preserved if the class does not have a Route annotation and did not have it at registration time
      • a route is preserved if the class is annotated with Route and registerAtStartup=false and the the flag has not changed
      • new classes are not automatically added to session registries
      • existing routes in session registries are not removed in case of class modification
      Parameters:
      registry - route registry
      addedClasses - added classes
      modifiedClasses - modified classes
      deletedClasses - deleted classes
      Since:
      3.1
    • isAutolayoutEnabled

      public static boolean isAutolayoutEnabled(Class<?> target, String path)
      Check if given route can get the automatic layout. Automatic layout can be used if it is a Route with no Route.layout() set and Route.autoLayout() as true.
      Parameters:
      target - target to check for accessibility
      path - path to determine if we are targeting a RouteAlias instead of Route
      Returns:
      true if auto layout can be used
      Since:
      24.5
    • checkForClientRouteCollisions

      public static void checkForClientRouteCollisions(VaadinService service, List<RouteData> flowRoutes) throws InvalidRouteConfigurationException
      Checks the given list of Flow routes for potential collisions with Hilla routes. Note: Routes will only be checked in development mode, when Hilla is in use.
      Parameters:
      service - VaadinService instance
      flowRoutes - Flow routes to check against
      Throws:
      InvalidRouteConfigurationException - if a collision is detected
      Since:
      24.5.1
    • checkForClientRouteCollisions

      public static void checkForClientRouteCollisions(VaadinService service, String... flowRouteTemplates) throws InvalidRouteConfigurationException
      Checks the given array of Flow route templates for potential collisions with Hilla routes. Note: Routes will only be checked in development mode, when Hilla is in use.
      Parameters:
      service - VaadinService instance
      flowRouteTemplates - Flow routes to check against
      Throws:
      InvalidRouteConfigurationException - if a collision is detected
      Since:
      24.5.1
    • hasAutoLayout

      public static boolean hasAutoLayout(AbstractRouteRegistry registry)
      Check if the given registry has any auto layouts added with @Layout annotation.
      Parameters:
      registry - the registry to check
      Returns:
      true if the registry has any auto layouts
      Since:
      24.5
    • hasClientRouteWithAutoLayout

      public static boolean hasClientRouteWithAutoLayout(AbstractConfiguration configuration)
      Check if currently registered client routes use auto layout based on AvailableViewInfo.flowLayout().
      Parameters:
      configuration - deployment configuration
      Returns:
      true if any client route has auto layout
      Since:
      24.5
    • hasServerRouteWithAutoLayout

      public static boolean hasServerRouteWithAutoLayout(AbstractRouteRegistry registry)
      Check if the given registry has any routes using auto layout.
      Parameters:
      registry - the registry to check
      Returns:
      true if the registry has any auto layouts
      Since:
      24.5
    • getDynamicTitle

      public static Optional<String> getDynamicTitle(UI ui)
      Get optional dynamic page title from the active router targets chain of a given UI instance.
      Parameters:
      ui - instance of UI, not null
      Returns:
      dynamic page title found in the routes chain, or empty optional if no implementor of HasDynamicTitle was found
      Since:
      24.5
    • getRouteParent

      public static Optional<RouteReference> getRouteParent(RouteRegistry registry, Class<? extends Component> navigationTarget, RouteParameters parameters)
      Resolves the logical parent of the given navigation target, without instantiating the route or its parent.

      The parent is resolved in this order:

      1. if the target has a RouteParent annotation, its dynamic RouteParent.resolver() or static RouteParent.value() is used (the resolver takes precedence; a static parent inherits the target route parameters narrowed to the parent's own template);
      2. otherwise the parent is derived from the route URL by walking up the registered route serving the nearest ancestor path.
      Parameters:
      registry - the route registry used to resolve URL-derived parents and parameter templates, may be null to resolve only annotation-based parents
      navigationTarget - the navigation target to resolve the logical parent for, not null
      parameters - the route parameters the navigation target is resolved with, not null
      Returns:
      the logical parent reference, or an empty Optional if the target has no logical parent
      Since:
      25.2
    • getRouteHierarchy

      public static List<RouteReference> getRouteHierarchy(RouteRegistry registry, Class<? extends Component> navigationTarget, RouteParameters parameters)
      Resolves the logical route hierarchy of the given navigation target by repeatedly resolving the route parent (see getRouteParent(RouteRegistry, Class, RouteParameters)), without instantiating any of the routes.

      The returned list is the chain of the target and all its logical ancestors, ordered from the hierarchy root to the given navigation target (the target itself is the last element). Each entry carries the route parameters it should be resolved with, so the title of every entry can be resolved with MenuRegistry.getTitle(Class, RouteParameters) (which honors PageTitleGenerator). This is what a breadcrumb or a hierarchical menu is built from. A guard stops the walk if the hierarchy contains a cycle.

      Parameters:
      registry - the route registry used to resolve URL-derived parents and parameter templates, may be null to resolve only annotation-based parents
      navigationTarget - the navigation target to resolve the hierarchy for, not null
      parameters - the route parameters the navigation target is resolved with, not null
      Returns:
      the chain of the target and its logical ancestors, ordered from root to the navigation target, never empty
      Since:
      25.2
    • getClientNavigationRouteTargetTemplate

      public static Optional<String> getClientNavigationRouteTargetTemplate(String url)
      Search for a client route using given navigation url and return target template.
      Parameters:
      url - the navigation url used to search a route target.
      Returns:
      a Optional containing the template of the client route target or an empty Optional.
      Since:
      24.5.1