public interface Navigator extends Serializable
Router to implement the
actual routing.
A route is decalred using the Route annotation and bound to a navigation path. See the Router
documentation for more information about route definitions and routing layouts.
The Navigator supports navigation parameters declaration and mapping, performing the parameters value
serialization to translate the Java type values into the String type URL parameter values.
It provides the navigateBack() method to navigate back in the browser history.
The get() static method can be used to obtain the Navigator reference for the current UI.
QueryParameter,
NavigationParameterMapper| Modifier and Type | Interface and Description |
|---|---|
static interface |
Navigator.NavigationBuilder
A builder to create a navigation location and trigger the navigation action.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
CONTEXT_KEY
Default
Context resource key. |
static String |
DEFAULT_NAVIGATION_FAILED_MESSAGE
Default navigation failed error message.
|
static String |
DEFAULT_NAVIGATION_FAILED_MESSAGE_CODE
Default navigation failed error message localization code.
|
| Modifier and Type | Method and Description |
|---|---|
com.holonplatform.core.Registration |
addNavigationChangeListener(NavigationChangeListener navigationChangeListener)
Add a
NavigationChangeListener to listen to navigation target/location changes. |
static Navigator |
create(com.vaadin.flow.component.UI ui)
Create a new
Navigator bound to given UI. |
static Navigator |
get()
Get the
Navigator bound to the current UI. |
<T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
getUrl(Class<? extends C> navigationTarget,
List<T> parameters)
Get the registered URL for given navigation target class, including the given
parameters in the url. |
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
getUrl(Class<? extends C> navigationTarget,
T... parameters)
Get the registered URL for given navigation target class, including the given
parameters in the url. |
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
getUrl(Class<? extends C> navigationTarget,
T parameter)
Get the registered URL for given navigation target class, including the given
parameter in the url. |
String |
getUrl(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
Get the registered URL for given navigation target class.
|
void |
navigateBack()
Navigates back.
|
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
navigateTo(Class<? extends C> navigationTarget,
List<T> pathParameters)
Navigate to the given navigation target and provide the given
pathParameters in the URL. |
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
navigateTo(Class<? extends C> navigationTarget,
List<T> pathParameters,
Map<String,Object> queryParameters)
Navigate to the given navigation target, providing the given
pathParameters in the URL and the given
query parameters. |
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
navigateTo(Class<? extends C> navigationTarget,
T pathParameter)
Navigate to the given navigation target and provide the given
pathParameter in the URL. |
default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> |
navigateTo(Class<? extends C> navigationTarget,
T pathParameter,
Map<String,Object> queryParameters)
Navigate to the given navigation target, providing the given
pathParameter in the URL and the given
query parameters. |
default void |
navigateTo(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
Navigate to the given navigation target.
|
default void |
navigateTo(Class<? extends com.vaadin.flow.component.Component> navigationTarget,
Map<String,Object> queryParameters)
Navigate to the given navigation target, using the provided query parameters.
|
default void |
navigateTo(String path)
Navigate to the given path.
|
void |
navigateTo(String path,
Map<String,Object> queryParameters)
Navigate to the given path, using the provided query parameters.
|
void |
navigateToDefault()
Navigates to the default navigation target, i.e.
|
void |
navigateToLocation(String location)
Navigate to the given location.
|
void |
navigateToPrevious()
Navigates to the previous route, if available.
|
default Navigator.NavigationBuilder |
navigation(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
Gets a
Navigator.NavigationBuilder to fluently build a navigation location for the given
navigationTarget, including any URL query parameter. |
default Navigator.NavigationBuilder |
navigation(String path)
Gets a
Navigator.NavigationBuilder to fluently build a navigation location for the given path,
including any URL query parameter. |
static final String DEFAULT_NAVIGATION_FAILED_MESSAGE
static final String DEFAULT_NAVIGATION_FAILED_MESSAGE_CODE
static final String CONTEXT_KEY
Context resource key.void navigateToLocation(String location)
The location may include a set of query path parameters, using the default ? separator.
location - The location to navigate to. If null, the default ("") location will be
useddefault void navigateTo(String path)
path - The path to navigate to. If null, the default ("") path will be usedvoid navigateTo(String path, Map<String,Object> queryParameters)
The query parameter values will be serialized to be included in the navigation location URL, using a
NavigationParameterMapper. See the QueryParameter annotation to learn about the supported query
parameter value types.
path - The path to navigate to. If null, the default ("") path will be usedqueryParameters - A map of query parameters, which associates the parameter names to their valuesdefault void navigateTo(Class<? extends com.vaadin.flow.component.Component> navigationTarget, Map<String,Object> queryParameters)
The query parameter values will be serialized to be included in the navigation location URL, using a
NavigationParameterMapper. See the QueryParameter annotation to learn about the supported query
parameter value types.
The navigation target must be declared as a route, for example using the Route annotation.
navigationTarget - The navigation target to navigate to (not null)queryParameters - A map of query parameters, which associates the parameter names to their valuesdefault void navigateTo(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
The navigation target must be declared as a route, for example using the Route annotation.
navigationTarget - The navigation target to navigate to (not null)default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> void navigateTo(Class<? extends C> navigationTarget, T pathParameter)
pathParameter in the URL.
The navigation target must be declared as a route and implement the HasUrlParameter interface.
T - Path parameter typeC - Navigation target typenavigationTarget - The navigation target to navigate to (not null)pathParameter - The parameter to include into the navigation urldefault <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> void navigateTo(Class<? extends C> navigationTarget, List<T> pathParameters)
pathParameters in the URL.
The navigation target must be declared as a route and implement the HasUrlParameter interface.
T - Path parameter typeC - Navigation target typenavigationTarget - The navigation target to navigate to (not null)pathParameters - The parameters to include into the navigation urldefault <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> void navigateTo(Class<? extends C> navigationTarget, T pathParameter, Map<String,Object> queryParameters)
pathParameter in the URL and the given
query parameters.
The navigation target must be declared as a route and implement the HasUrlParameter interface.
T - Path parameter typeC - Navigation target typenavigationTarget - The navigation target to navigate to (not null)pathParameter - The parameter to include into the navigation url (not null)queryParameters - A map of query parameters, which associates the parameter names to their valuesdefault <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> void navigateTo(Class<? extends C> navigationTarget, List<T> pathParameters, Map<String,Object> queryParameters)
pathParameters in the URL and the given
query parameters.
The navigation target must be declared as a route and implement the HasUrlParameter interface.
T - Path parameter typeC - Navigation target typenavigationTarget - The navigation target to navigate to (not null)pathParameters - The parameters to include into the navigation url (not null)queryParameters - A map of query parameters, which associates the parameter names to their valuesvoid navigateToDefault()
"" route path.void navigateBack()
This has the same effect as if the user would press the back button in the browser.
void navigateToPrevious()
This method can be used to navigate back in the route targets sequence handled by the UI Router or Navigator, it
has not the same effect and purpose of the navigateBack() method, which can be used to navigate back in
the browser history.
navigateToDefault()default Navigator.NavigationBuilder navigation(String path)
Navigator.NavigationBuilder to fluently build a navigation location for the given path,
including any URL query parameter.
The Navigator.NavigationBuilder.navigate() can be used to trigger the actual navigation. Otherwise, the navigation
location can be obtained as a Location, using Navigator.NavigationBuilder.asLocation() or as a URL, using
Navigator.NavigationBuilder.asLocationURL().
path - The path to navigate to. If null, the default ("") path will be usedNavigator.NavigationBuilderdefault Navigator.NavigationBuilder navigation(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
Navigator.NavigationBuilder to fluently build a navigation location for the given
navigationTarget, including any URL query parameter.
The Navigator.NavigationBuilder.navigate() can be used to trigger the actual navigation. Otherwise, the navigation
location can be obtained as a Location, using Navigator.NavigationBuilder.asLocation() or as a URL, using
Navigator.NavigationBuilder.asLocationURL().
navigationTarget - The navigation target to navigate to (not null)Navigator.NavigationBuilderString getUrl(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
This method ignores any declared URL parameter, and always returns the navigation target base URL. To obtain the
URL for a navigation target with required URL parameters, use getUrl(Class, List) or
getUrl(Class, Object).
navigationTarget - The navigation target to get URL for (not null)default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter)
parameter in the url.T - URL parameter typeC - Navigation target typenavigationTarget - The navigation target to get url for (not null)parameter - The parameter to include in the generated URL (not null)default <T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T... parameters)
parameters in the url.T - URL parameters typeC - Navigation target typenavigationTarget - The navigation target to get url for (not null)parameters - The parameters to include in the generated URL (not null)<T,C extends com.vaadin.flow.component.Component & com.vaadin.flow.router.HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters)
parameters in the url.T - URL parameters typeC - Navigation target typenavigationTarget - The navigation target to get url for (not null)parameters - The parameters to include in the generated URL (not null)com.holonplatform.core.Registration addNavigationChangeListener(NavigationChangeListener navigationChangeListener)
NavigationChangeListener to listen to navigation target/location changes.navigationChangeListener - The listener to add (not null)static Navigator get()
Navigator bound to the current UI.
If a Navigator is available as a Context resource using the CONTEXT_KEY resource key,
that instance is returned.
Otherwise, if a Navigator session registry is available, it is used to obtain the Navigator bound
the current UI, or a new Navigator instance is created and returned is the session registry is missing.
When a Navigator is not available as a Context resource, the UI.getCurrent() method is
used to obtain the current UI and if it is not available an IllegalStateException is thrown.
Navigator bound to the current UIIllegalStateException - If a Navigator is not available from Context and the current UI is
not available through UI.getCurrent()Copyright © 2020 The Holon Platform. All rights reserved.