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 protected Optional<ErrorTargetEntry>
getErrorNavigationTarget(Exception exception)
RouteRegistry
getRegistry()
List<RouteData>
getRoutes()
Deprecated.
Url handling is moved toRouteConfiguration.getAvailableRoutes()
Map<Class<? extends RouterLayout>,List<RouteData>>
getRoutesByParent()
Deprecated.
No replacement.<T,C extends Component & HasUrlParameter<T>>
StringgetUrl(Class<? extends C> navigationTarget, List<T> parameters)
Deprecated.
Url handling is moved toRouteConfiguration.getUrl(Class, List)
<T,C extends Component & HasUrlParameter<T>>
StringgetUrl(Class<? extends C> navigationTarget, T parameter)
Deprecated.
Url handling is moved toRouteConfiguration.getUrl(Class, Object)
String
getUrl(Class<? extends Component> navigationTarget)
Deprecated.
Url handling is moved toRouteConfiguration.getUrl(Class)
String
getUrlBase(Class<? extends Component> navigationTarget)
Deprecated.
Url base handling is moved toRouteConfiguration.getUrlBase(Class)
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.
int
navigate(UI ui, Location location, NavigationTrigger trigger, elemental.json.JsonValue state)
Navigates the given UI to the given location.
static String
resolve(Class<?> component, Route route)
Deprecated.
UseRouteUtil.resolve(Class, Route)
insteadOptional<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:
-
navigate
public int navigate(UI ui, Location location, NavigationTrigger trigger, elemental.json.JsonValue state)
Navigates the given UI to the given location. For internal use only.
This method pushes to the browser history if the
trigger
isNavigationTrigger.ROUTER_LINK
orNavigationTrigger.UI_NAVIGATE
.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
state
- includes navigation state info including for example the scroll position and the complete href of the RouterLinkReturns:
the HTTP status code resulting from the navigation
See Also:
-
getUrl
@Deprecated public String getUrl(Class<? extends Component> navigationTarget)
Deprecated. Url handling is moved to
RouteConfiguration.getUrl(Class)
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
@Deprecated public String getUrlBase(Class<? extends Component> navigationTarget)
Deprecated. Url base handling is moved to
RouteConfiguration.getUrlBase(Class)
Return the url base without any url parameters.
Parameters:
navigationTarget
- navigation target to get url forReturns:
url base without url parameters
-
getUrl
@Deprecated public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter)
Deprecated. Url handling is moved to
RouteConfiguration.getUrl(Class, Object)
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
@Deprecated public <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters)
Deprecated. Url handling is moved to
RouteConfiguration.getUrl(Class, List)
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
@Deprecated public List<RouteData> getRoutes()
Deprecated. Url handling is moved to
RouteConfiguration.getAvailableRoutes()
Get all available routes.
Returns:
RouteData for all registered routes
-
getRoutesByParent
@Deprecated public Map<Class<? extends RouterLayout>,List<RouteData>> getRoutesByParent()
Deprecated. No replacement.
Get all available routes collected by parent layout.
Returns:
map of parent url to route
-
resolve
@Deprecated public static String resolve(Class<?> component, Route route)
Deprecated. Use
RouteUtil.resolve(Class, Route)
insteadGets 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.
-
getErrorNavigationTarget
protected Optional<ErrorTargetEntry> getErrorNavigationTarget(Exception exception)
-
-