com.vaadin.flow.router.
Class Router
- java.lang.Object
-
- com.vaadin.flow.router.Router
-
All Implemented Interfaces:
public class Router extends Object implements Serializable
The router takes care of serving content when the user navigates within a site or an application.
Since:
1.0.
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description Router(RouteRegistry registry)
Constructs a new router with the given route registry and a
DefaultRouteResolver
.
-
Method Summary
All Methods Modifier and Type Method and Description RouteRegistry
getRegistry()
List<RouteData>
getRoutes()
Get all available routes.
Map<Class<? extends RouterLayout>,List<RouteData>>
getRoutesByParent()
Get all available routes collected by parent layout.
<T,C extends Component & HasUrlParameter<T>>
StringgetUrl(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>>
StringgetUrl(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
getUrlBase(Class<? extends Component> navigationTarget)
Return the url base without any url parameters.
void
initializeUI(UI ui, VaadinRequest initRequest)
Enables navigation for a new UI instance.
int
navigate(UI ui, Location location, NavigationTrigger trigger)
Navigates the given UI to the given location.
static String
resolve(Class<?> component, Route route)
Gets the effective route path value of the annotated class.
Optional<NavigationState>
resolveNavigationTarget(String pathInfo, Map<String,String[]> parameterMap)
Resolve the navigation target for given path and parameter map using the router routeResolver.
-
-
-
Constructor Detail
-
Router
public Router(RouteRegistry registry)
Constructs a new router with the given route registry and a
DefaultRouteResolver
.Parameters:
registry
- the route registry to use, notnull
-
-
Method Detail
-
initializeUI
public void initializeUI(UI ui, VaadinRequest initRequest)
Enables navigation for a new UI instance. This initializes the UI content based on the location used for loading the UI and sets up the UI to be updated when the user navigates to some other location.
Parameters:
ui
- the UI that navigation should be set up forinitRequest
- the Vaadin request that bootstraps the provided UI
-
resolveNavigationTarget
public Optional<NavigationState> resolveNavigationTarget(String pathInfo, Map<String,String[]> parameterMap)
Resolve the navigation target for given path and parameter map using the router routeResolver.
Parameters:
pathInfo
- the path relative to the applicationparameterMap
- A mapping of parameter names to arrays of parameter valuesReturns:
NavigationTarget for the given path and parameter map if found
-
navigate
public int navigate(UI ui, Location location, NavigationTrigger trigger)
Navigates the given UI to the given location.
This method just shows the given
location
on the page and doesn't update the browser location (and page history). Use theUI.navigate(String, QueryParameters)
method if you want to update the browser location as well.Parameters:
ui
- the UI to update, notnull
location
- the location to navigate to, notnull
trigger
- the type of user action that triggered this navigation, notnull
Returns:
the HTTP status code resulting from the navigation
See Also:
-
getUrl
public String getUrl(Class<? extends Component> navigationTarget)
Get the registered url string for given navigation target.
Note! If the navigation target has a url parameter that is required then this method will throw and IllegalArgumentException.
Parameters:
navigationTarget
- navigation target to get url forReturns:
url for the navigation target
Throws:
IllegalArgumentException
- if the navigation target requires a parameter
-
getUrlBase
public String getUrlBase(Class<? extends Component> navigationTarget)
Return the url base without any url parameters.
Parameters:
navigationTarget
- navigation target to get url forReturns:
url base without url parameters
-
getUrl
public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter)
Get the url string for given navigation target with the parameter in the url.
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 aString
will fail.Type Parameters:
T
- url parameter typeC
- navigation target typeParameters:
navigationTarget
- navigation target to get url forparameter
- parameter to embed into the generated urlReturns:
url for the navigation target with parameter
-
getUrl
public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters)
Get the url string for given navigation target with the parameters in the url.
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 aString
will fail.Type Parameters:
T
- url parameter typeC
- navigation target typeParameters:
navigationTarget
- navigation target to get url forparameters
- parameters to embed into the generated url, not nullReturns:
url for the navigation target with parameter
-
getRegistry
public RouteRegistry getRegistry()
-
getRoutes
public List<RouteData> getRoutes()
Get all available routes.
Returns:
RouteData for all registered routes
-
getRoutesByParent
public Map<Class<? extends RouterLayout>,List<RouteData>> getRoutesByParent()
Get all available routes collected by parent layout.
Returns:
map of parent url to route
-
resolve
public static String resolve(Class<?> component, Route route)
Gets the effective route path value of the annotated class.
Parameters:
component
- the component where the route points toroute
- the annotationReturns:
The value of the annotation or naming convention based value if no explicit value is given.
-
-