Package com.vaadin.flow.router.internal
Class RouteUtil
java.lang.Object
com.vaadin.flow.router.internal.RouteUtil
Utility class with methods for route handling.
For internal use only. May be renamed or removed in a future release.
- Since:
- 1.3
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckForClientRouteCollisions(VaadinService service, String... flowRouteTemplates) Checks the given array of Flow route templates for potential collisions with Hilla routes.static voidcheckForClientRouteCollisions(VaadinService service, List<RouteData> flowRoutes) Checks the given list of Flow routes for potential collisions with Hilla routes.static List<Class<? extends RouterLayout>> collectRouteParentLayouts(Class<? extends RouterLayout> layout) Collects all parent layouts for a given route layout class.Search for a client route using given navigation url and return target template.getDynamicTitle(UI ui) Get optional dynamic page title from the active router targets chain of a given UI instance.static List<Class<? extends RouterLayout>> getParentLayouts(RouteRegistry handledRegistry, Class<?> component, String path) Get parent layouts for navigation target according to theRouteorRouteAliasannotation or automatically link RouterLayout annotated with theLayoutannotation matching route path.static List<Class<? extends RouterLayout>> getParentLayouts(VaadinContext context, Class<?> component, String path) Get parent layouts for navigation target according to theRouteorRouteAliasannotation.static List<Class<? extends RouterLayout>> getParentLayoutsForNonRouteTarget(Class<?> navigationTarget) Collect possible route parent layouts for a navigation target that is not annotated withRoutenorRouteAlias, but may still containParentLayout.static StringgetRouteAliasPath(Class<?> component, RouteAlias alias) Get the actual route path including all parent layoutRoutePrefix.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 (seegetRouteParent(RouteRegistry, Class, RouteParameters)), without instantiating any of the routes.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.static StringgetRoutePath(VaadinContext context, Class<?> component) Get the actual route path including all parent layoutRoutePrefix.static Class<? extends RouterLayout> getTopParentLayout(VaadinContext context, Class<?> component, String path) Get the top most parent layout for navigation target according to theRouteorRouteAliasannotation.static booleanhasAutoLayout(AbstractRouteRegistry registry) Check if the given registry has any auto layouts added with @Layoutannotation.static booleanhasClientRouteWithAutoLayout(AbstractConfiguration configuration) Check if currently registered client routes use auto layout based onAvailableViewInfo.flowLayout().static booleanCheck if the given registry has any routes using auto layout.static booleanisAutolayoutEnabled(Class<?> target, String path) Check if given route can get the automatic layout.static Stringresolve(VaadinContext context, Class<?> component) Gets the effective route path value of the annotated class.static voidupdateRouteRegistry(RouteRegistry registry, Set<Class<?>> addedClasses, Set<Class<?>> modifiedClasses, Set<Class<?>> deletedClasses) Updates route registry as necessary when classes have been added / modified / deleted.
-
Field Details
-
ROUTE_CONFLICT
- See Also:
-
ROUTE_CONFLICT_WITH_PARAMS
- See Also:
-
-
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 theRouteorRouteAliasannotation.- Parameters:
context- a Vaadin contextcomponent- navigation target to get parents forpath- 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 theRouteorRouteAliasannotation or automatically link RouterLayout annotated with theLayoutannotation matching route path.- Parameters:
handledRegistry- current routeRegistrycomponent- navigation target to get parents forpath- path used to get navigation target so we know which annotation to handle- Returns:
- parent layouts for target
- Since:
- 24.5
-
getRoutePath
Get the actual route path including all parent layoutRoutePrefix.- Parameters:
context- a Vaadin contextcomponent- navigation target component to get route path for- Returns:
- actual path for given route target
- Since:
- 9.0
-
getRouteAliasPath
Get the actual route path including all parent layoutRoutePrefix.- Parameters:
component- navigation target component to get route path foralias- 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 withRoutenorRouteAlias, but may still containParentLayout. 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 theRouteorRouteAliasannotation. Also handles non route targets withParentLayout.- Parameters:
context- a Vaadin contextcomponent- navigation target to get top most parent forpath- 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
Gets the effective route path value of the annotated class.- Parameters:
context- a Vaadin contextcomponent- 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
Routeannotation and did not have it at registration time - a route is preserved if the class is annotated with
RouteandregisterAtStartup=falseand 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 registryaddedClasses- added classesmodifiedClasses- modified classesdeletedClasses- deleted classes- Since:
- 3.1
- a route is preserved if the class does not have a
-
isAutolayoutEnabled
Check if given route can get the automatic layout. Automatic layout can be used if it is aRoutewith noRoute.layout()set andRoute.autoLayout()as true.- Parameters:
target- target to check for accessibilitypath- path to determine if we are targeting aRouteAliasinstead ofRoute- Returns:
trueif 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 instanceflowRoutes- 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 instanceflowRouteTemplates- Flow routes to check against- Throws:
InvalidRouteConfigurationException- if a collision is detected- Since:
- 24.5.1
-
hasAutoLayout
Check if the given registry has any auto layouts added with @Layoutannotation.- Parameters:
registry- the registry to check- Returns:
trueif the registry has any auto layouts- Since:
- 24.5
-
hasClientRouteWithAutoLayout
Check if currently registered client routes use auto layout based onAvailableViewInfo.flowLayout().- Parameters:
configuration- deployment configuration- Returns:
trueif any client route has auto layout- Since:
- 24.5
-
hasServerRouteWithAutoLayout
Check if the given registry has any routes using auto layout.- Parameters:
registry- the registry to check- Returns:
trueif the registry has any auto layouts- Since:
- 24.5
-
getDynamicTitle
Get optional dynamic page title from the active router targets chain of a given UI instance.- Parameters:
ui- instance of UI, notnull- Returns:
- dynamic page title found in the routes chain, or empty optional
if no implementor of
HasDynamicTitlewas 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:
- if the target has a
RouteParentannotation, its dynamicRouteParent.resolver()or staticRouteParent.value()is used (the resolver takes precedence; a static parent inherits the target route parameters narrowed to the parent's own template); - 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 benullto resolve only annotation-based parentsnavigationTarget- the navigation target to resolve the logical parent for, notnullparameters- the route parameters the navigation target is resolved with, notnull- Returns:
- the logical parent reference, or an empty
Optionalif the target has no logical parent - Since:
- 25.2
- if the target has a
-
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 (seegetRouteParent(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 honorsPageTitleGenerator). 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 benullto resolve only annotation-based parentsnavigationTarget- the navigation target to resolve the hierarchy for, notnullparameters- the route parameters the navigation target is resolved with, notnull- Returns:
- the chain of the target and its logical ancestors, ordered from root to the navigation target, never empty
- Since:
- 25.2
-