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
  • 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
    • 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
    • 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
    • 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.
    • 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:
      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
    • 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.
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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.