Package com.vaadin.flow.router
Class Router
- java.lang.Object
-
- com.vaadin.flow.router.Router
-
- All Implemented Interfaces:
Serializable
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:
Route
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Router(RouteRegistry registry)
Constructs a new router with the given route registry and aDefaultRouteResolver
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Optional<ErrorTargetEntry>
getErrorNavigationTarget(Exception exception)
Get a registered navigation target for given exception.RouteRegistry
getRegistry()
void
initializeUI(UI ui, Location location)
Enables navigation for a new UI instance.void
initializeUI(UI ui, VaadinRequest initRequest)
Deprecated.useinitializeUI(UI, Location)
insteadint
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.Optional<NavigationState>
resolveNavigationTarget(Location location)
Resolve the navigation target for givenLocation
using the router routeResolver.Optional<NavigationState>
resolveNavigationTarget(String pathInfo, Map<String,String[]> parameterMap)
Resolve the navigation target for given path and parameter map using the router routeResolver.Optional<NavigationState>
resolveRouteNotFoundNavigationTarget()
Resolve a navigation target with an emptyNotFoundException
.
-
-
-
Constructor Detail
-
Router
public Router(RouteRegistry registry)
Constructs a new router with the given route registry and aDefaultRouteResolver
.- Parameters:
registry
- the route registry to use, notnull
-
-
Method Detail
-
initializeUI
@Deprecated public void initializeUI(UI ui, VaadinRequest initRequest)
Deprecated.useinitializeUI(UI, Location)
insteadEnables 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
-
initializeUI
public void initializeUI(UI ui, Location location)
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 forlocation
- the location object of the route
-
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 values- Returns:
- NavigationTarget for the given path and parameter map if found
-
resolveNavigationTarget
public Optional<NavigationState> resolveNavigationTarget(Location location)
Resolve the navigation target for givenLocation
using the router routeResolver.- Parameters:
location
- the location object of the route- Returns:
- NavigationTarget for the given location if found
-
resolveRouteNotFoundNavigationTarget
public Optional<NavigationState> resolveRouteNotFoundNavigationTarget()
Resolve a navigation target with an emptyNotFoundException
.- Returns:
- an instance of
NavigationState
for NotFoundException or empty if there is none in the application.
-
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:
UI.navigate(String)
,UI.navigate(String, QueryParameters)
-
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 RouterLink- Returns:
- the HTTP status code resulting from the navigation
- See Also:
UI.navigate(String)
,UI.navigate(String, QueryParameters)
-
getRegistry
public RouteRegistry getRegistry()
-
getErrorNavigationTarget
public Optional<ErrorTargetEntry> getErrorNavigationTarget(Exception exception)
Get a registered navigation target for given exception.- Parameters:
exception
- exception to search error view for- Returns:
- optional error target entry corresponding to the given exception
-
-