Package com.vaadin.flow.router
Class Router
java.lang.Object
com.vaadin.flow.router.Router
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionRouter(RouteRegistry registry) Constructs a new router with the given route registry and aDefaultRouteResolver. -
Method Summary
Modifier and TypeMethodDescriptionintexecuteNavigation(UI ui, Location location, NavigationEvent navigationEvent, NavigationHandler handler, IntConsumer onSuccess) Execute navigation with a pre-resolved handler and optional success callback.getErrorNavigationTarget(Exception exception) Get a registered navigation target for given exception.inthandleExceptionNavigation(UI ui, Location location, Exception exception, NavigationTrigger trigger, tools.jackson.databind.node.BaseJsonNode state) Render error view for exception.voidinitializeUI(UI ui, Location location) Enables navigation for a new UI instance.intnavigate(UI ui, Location location, NavigationTrigger trigger) Navigates the given UI to the given location.intnavigate(UI ui, Location location, NavigationTrigger trigger, tools.jackson.databind.node.BaseJsonNode state) Navigates the given UI to the given location.intnavigate(UI ui, Location location, NavigationTrigger trigger, tools.jackson.databind.node.BaseJsonNode state, boolean forceInstantiation, boolean recreateLayoutChain) Navigates the given UI to the given location.resolveNavigationTarget(Location location) Resolve the navigation target for givenLocationusing the router routeResolver.resolveNavigationTarget(String pathInfo, Map<String, String[]> parameterMap) Resolve the navigation target for given path and parameter map using the router routeResolver.resolvePageTitle(Component navigationTarget, RouteParameters routeParameters) Resolves the page title of the given navigation target instance, using empty query parameters.resolvePageTitle(Component navigationTarget, RouteParameters routeParameters, QueryParameters queryParameters) Resolves the page title of the given navigation target instance.resolvePageTitle(Class<? extends Component> navigationTarget, RouteParameters routeParameters) Resolves the page title of the given navigation target without creating an instance of it, using empty query parameters.resolvePageTitle(Class<? extends Component> navigationTarget, RouteParameters routeParameters, QueryParameters queryParameters) Resolves the page title of the given navigation target without creating an instance of it.Resolve a navigation target with an emptyNotFoundException.
-
Constructor Details
-
Router
Constructs a new router with the given route registry and aDefaultRouteResolver.- Parameters:
registry- the route registry to use, notnull
-
-
Method Details
-
initializeUI
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- Since:
- 3.0
-
resolvePageTitle
public Optional<String> resolvePageTitle(Class<? extends Component> navigationTarget, RouteParameters routeParameters) Resolves the page title of the given navigation target without creating an instance of it, using empty query parameters.- Parameters:
navigationTarget- the navigation target to resolve the title for, notnullrouteParameters- the route parameters the target is resolved with, notnull- Returns:
- the resolved title, or an empty
Optionalif the target declares no title and no default generator is available - Since:
- 25.2
- See Also:
-
resolvePageTitle
public Optional<String> resolvePageTitle(Class<? extends Component> navigationTarget, RouteParameters routeParameters, QueryParameters queryParameters) Resolves the page title of the given navigation target without creating an instance of it.The title is resolved in this order:
- the per-route
DynamicPageTitlegenerator; - the application-wide default
PageTitleGenerator; - the static
PageTitle.value().
VaadinService; when no service is active, only annotation-based resolution is performed.Since the navigation target is not instantiated,
HasDynamicTitle.getPageTitle()is not consulted; the title of an instantiated, currently shown route may therefore differ from the result of this method. This is the stateless title resolution used to render navigation aids such as breadcrumbs and menus, for example over the entries ofRouteConfiguration.getRouteHierarchy(Class, RouteParameters).- Parameters:
navigationTarget- the navigation target to resolve the title for, notnullrouteParameters- the route parameters the target is resolved with, notnullqueryParameters- the query parameters the target is resolved with, notnull- Returns:
- the resolved title, or an empty
Optionalif the target declares no title and no default generator is available - Since:
- 25.2
- the per-route
-
resolvePageTitle
public Optional<String> resolvePageTitle(Component navigationTarget, RouteParameters routeParameters) Resolves the page title of the given navigation target instance, using empty query parameters.- Parameters:
navigationTarget- the navigation target instance to resolve the title for, notnullrouteParameters- the route parameters the target is resolved with, notnull- Returns:
- the resolved title, or an empty
Optionalif the target declares no title and no default generator is available - Since:
- 25.2
- See Also:
-
resolvePageTitle
public Optional<String> resolvePageTitle(Component navigationTarget, RouteParameters routeParameters, QueryParameters queryParameters) Resolves the page title of the given navigation target instance.The title is resolved in this order:
HasDynamicTitle.getPageTitle(), when the instance implementsHasDynamicTitleand returns a non-nulltitle — this matches the title shown when the route is actually navigated to;- the per-route
DynamicPageTitlegenerator; - the application-wide default
PageTitleGenerator; - the static
PageTitle.value().
resolvePageTitle(Class, RouteParameters, QueryParameters), which cannot create an instance and therefore skipsHasDynamicTitle, this overload mirrors the resolution performed during navigation.- Parameters:
navigationTarget- the navigation target instance to resolve the title for, notnullrouteParameters- the route parameters the target is resolved with, notnullqueryParameters- the query parameters the target is resolved with, notnull- Returns:
- the resolved title, or an empty
Optionalif the target declares no title and no default generator is available - Since:
- 25.2
-
getRegistry
-