public class RouteConfiguration extends Object implements Serializable
Modifier and Type | Method and Description |
---|---|
Registration |
addRoutesChangeListener(RoutesChangedListener listener)
Add a listener that is notified when routes change for the registry.
|
static RouteConfiguration |
forApplicationScope()
Get a
RouteConfiguration that edits the application scope routes. |
static RouteConfiguration |
forRegistry(RouteRegistry registry)
Get a
RouteConfiguration for editing the given RouteRegistry
implementation. |
static RouteConfiguration |
forSessionScope()
Get a
RouteConfiguration that edits the session scope routes. |
List<RouteData> |
getAvailableRoutes()
Get the
RouteData for all registered navigation targets. |
RouteRegistry |
getHandledRegistry()
Get the registry that this configuration is working with.
|
Optional<Class<? extends Component>> |
getRoute(String path)
Gets the registered route class for a given path.
|
Optional<Class<? extends Component>> |
getRoute(String path,
List<String> segments)
Gets the optional navigation target class for a given Location matching
with path segments.
|
Optional<String> |
getTemplate(Class<? extends Component> navigationTarget)
Gets the route template for the given target.
|
<T,C extends Component & HasUrlParameter<T>> |
getUrl(Class<? extends C> navigationTarget,
List<T> parameters)
Get the url string for given navigation target with the parameters in the
url.
|
<T,C extends Component & HasUrlParameter<T>> |
getUrl(Class<? extends C> navigationTarget,
T parameter)
Get the url string for given navigation target with the parameter in the
url.
|
String |
getUrl(Class<? extends Component> navigationTarget)
Get the registered url string for given navigation target.
|
String |
getUrl(Class<? extends Component> navigationTarget,
RouteParameters parameters)
Gets the url which navigates to given navigationTarget using given
parameters.
|
Optional<String> |
getUrlBase(Class<? extends Component> navigationTarget)
Return the url base without any route parameters.
|
boolean |
isPathAvailable(String path)
Check if the given path is available.
|
boolean |
isPathRegistered(String path)
Deprecated.
|
boolean |
isRouteRegistered(Class<? extends Component> route)
Check if the route is available as a registered target.
|
void |
removeRoute(Class<? extends Component> navigationTarget)
Remove the given navigation target route registration.
|
void |
removeRoute(String path)
Remove all registrations for given path.
|
void |
removeRoute(String path,
Class<? extends Component> navigationTarget)
Remove only the specified navigationTarget from the path and not other
targets if they exist for the same path.
|
void |
setAnnotatedRoute(Class<? extends Component> navigationTarget)
Giving a navigation target here will handle the
Route annotation
to get the path and also register any RouteAlias that may be on
the class. |
void |
setParentAnnotatedRoute(String path,
Class<? extends Component> navigationTarget)
Register a navigation target on the specified path.
|
void |
setRoute(String path,
Class<? extends Component> navigationTarget)
Register a navigation target with specified path and with no parent
layouts.
|
void |
setRoute(String path,
Class<? extends Component> navigationTarget,
Class<? extends RouterLayout>... parentChain)
Register a navigation target with specified path and given parent layout
chain.
|
void |
setRoute(String path,
Class<? extends Component> navigationTarget,
List<Class<? extends RouterLayout>> parentChain)
Register a navigation target with specified path and given parent layout
chain.
|
void |
update(Command command)
Block updates to the registry configuration from other threads until
update command has completed.
|
public static RouteConfiguration forSessionScope()
RouteConfiguration
that edits the session scope routes.
This requires that VaadinSession.getCurrent()
is populated.
Note! Session scoped registry sees also the application scope routes.
public static RouteConfiguration forApplicationScope()
RouteConfiguration
that edits the application scope routes.
This requires that VaadinServlet.getCurrent()
is populated.public static RouteConfiguration forRegistry(RouteRegistry registry)
RouteConfiguration
for editing the given RouteRegistry
implementation. This enables editing of registry when the required
CurrentInstance
is not yet populated.registry
- registry to edit through the controllerpublic List<RouteData> getAvailableRoutes()
RouteData
for all registered navigation targets.
Note! This would be best to request for session scope registry as it will then contain the actual currently visible routes from both the session and application scopes.
Note! Size of the list is only main routes as RouteData will contain a list of alias route registrations.
@Deprecated public boolean isPathRegistered(String path)
isPathAvailable(String)
path
- path to check for route registrationpublic boolean isPathAvailable(String path)
path
- path to check for availabilitypublic boolean isRouteRegistered(Class<? extends Component> route)
route
- target class to check for registrationpublic Optional<Class<? extends Component>> getRoute(String path)
path
- path to get route forpublic Optional<Class<? extends Component>> getRoute(String path, List<String> segments)
path
- path to get navigation target for, not null
segments
- segments given for pathpublic Registration addRoutesChangeListener(RoutesChangedListener listener)
listener
- listener to addpublic void update(Command command)
Using this method makes the registry changes made inside the command atomic for the registry as no one else can change the state during the duration of the command.
Any other configuration thread for the same registry will be blocked until all the update locks have been released.
Note! During an update other threads will get the pre-update state of the registry until the update has fully completed.
command
- command to execute for the updatepublic void setAnnotatedRoute(Class<? extends Component> navigationTarget)
Route
annotation
to get the path and also register any RouteAlias
that may be on
the class.navigationTarget
- navigation target to registerInvalidRouteConfigurationException
- thrown if exact route already defined in this scopepublic void setParentAnnotatedRoute(String path, Class<? extends Component> navigationTarget)
ParentLayout
annotation on class will be used to populate layout
chain, but Route
and RouteAlias
will not be taken into
consideration.path
- path to register navigation target tonavigationTarget
- navigation target to registerInvalidRouteConfigurationException
- thrown if exact route already defined in this scopepublic void setRoute(String path, Class<? extends Component> navigationTarget)
Note! Any ParentLayout
, Route
or RouteAlias
will
be ignored in route handling.
path
- path to register navigation target tonavigationTarget
- navigation target to registerInvalidRouteConfigurationException
- thrown if exact route already defined in this scopepublic void setRoute(String path, Class<? extends Component> navigationTarget, List<Class<? extends RouterLayout>> parentChain)
Note! Any ParentLayout
, Route
or RouteAlias
will
be ignored in route handling.
path
- path to register navigation target tonavigationTarget
- navigation target to registerparentChain
- chain of parent layouts that should be used with this targetInvalidRouteConfigurationException
- thrown if exact route already defined in this scopepublic void setRoute(String path, Class<? extends Component> navigationTarget, Class<? extends RouterLayout>... parentChain)
Note! Any ParentLayout
, Route
or RouteAlias
will
be ignored in route handling.
path
- path to register navigation target tonavigationTarget
- navigation target to registerparentChain
- chain of parent layouts that should be used with this targetInvalidRouteConfigurationException
- thrown if exact route already defined in this scopepublic void removeRoute(Class<? extends Component> navigationTarget)
Note! this will remove target route and if possible any
RouteAlias
route that can be found for the class.
navigationTarget
- navigation target class to removepublic void removeRoute(String path)
E.g. path "home" contains HomeView and DetailsView[String path param] both will be removed.
Note! The restored path will be the first found match for all paths that are registered.
In case navigationTarget is a
HasUrlParameter
, path argument needs to
include the parameter placeholder which is added automatically.
Otherwise, using removeRoute(String, Class)
is preferred in such
a case.
path
- path for which to remove all navigation targetspublic void removeRoute(String path, Class<? extends Component> navigationTarget)
Note! If another path exists for the removed navigation target it will get a new main path so it can still get a resolved url. The restored path will be the first found match for all paths that are registered.
path
- path to remove from registrynavigationTarget
- path navigation target to removepublic RouteRegistry getHandledRegistry()
public String getUrl(Class<? extends Component> navigationTarget)
Note! If the navigation target has a url parameter that is required then this method will throw an IllegalArgumentException.
navigationTarget
- navigation target to get url forIllegalArgumentException
- if the navigation target requires a parameterpublic Optional<String> getUrlBase(Class<? extends Component> navigationTarget)
navigationTarget
- navigation target to get url fornavigationTarget
, not
null
public Optional<String> getTemplate(Class<? extends Component> navigationTarget)
navigationTarget
- target class.public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter)
Note! Given parameter is checked for correct class type. This means that
if the navigation target defined parameter is of type Boolean
then calling getUrl with a String
will fail.
T
- url parameter typeC
- navigation target typenavigationTarget
- navigation target to get url forparameter
- parameter to embed into the generated urlpublic <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters)
Note! Given parameters are checked for correct class type. This means
that if the navigation target defined parameter is of type
Boolean
then calling getUrl with a String
will fail.
T
- url parameter typeC
- navigation target typenavigationTarget
- navigation target to get url forparameters
- parameters to embed into the generated url, not nullpublic String getUrl(Class<? extends Component> navigationTarget, RouteParameters parameters)
navigationTarget
- navigation target.parameters
- route parameters.NotFoundException
- in case the navigationTarget is not registered with a url
template matching the given parameters.Copyright © 2025. All rights reserved.