public class Router extends Object implements Serializable
Route
,
Serialized FormConstructor and Description |
---|
Router(RouteRegistry registry)
Constructs a new router with the given route registry and a
DefaultRouteResolver . |
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>> |
getUrl(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>> |
getUrl(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.
|
public Router(RouteRegistry registry)
DefaultRouteResolver
.registry
- the route registry to use, not null
public void initializeUI(UI ui, VaadinRequest initRequest)
ui
- the UI that navigation should be set up forinitRequest
- the Vaadin request that bootstraps the provided UIpublic Optional<NavigationState> resolveNavigationTarget(String pathInfo, Map<String,String[]> parameterMap)
pathInfo
- the path relative to the applicationparameterMap
- A mapping of parameter names to arrays of parameter valuespublic int navigate(UI ui, Location location, NavigationTrigger trigger)
This method just shows the given location
on the page and doesn't
update the browser location (and page history). Use the
UI.navigate(String, QueryParameters)
method if you want to update
the browser location as well.
ui
- the UI to update, not null
location
- the location to navigate to, not null
trigger
- the type of user action that triggered this navigation, not
null
UI.navigate(String)
,
UI.navigate(String, QueryParameters)
public String getUrl(Class<? extends Component> navigationTarget)
Note! If the navigation target has a url parameter that is required then this method will throw and IllegalArgumentException.
navigationTarget
- navigation target to get url forIllegalArgumentException
- if the navigation target requires a parameterpublic String getUrlBase(Class<? extends Component> navigationTarget)
navigationTarget
- navigation target to get url forpublic <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, T parameter)
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 a String
will fail.
T
- url parameter typeC
- navigation target typenavigationTarget
- navigation target to get url forparameter
- parameter to embed into the generated urlpublic <T,C extends Component & HasUrlParameter<T>> String getUrl(Class<? extends C> navigationTarget, List<T> parameters)
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 a String
will fail.
T
- url parameter typeC
- navigation target typenavigationTarget
- navigation target to get url forparameters
- parameters to embed into the generated url, not nullpublic RouteRegistry getRegistry()
public List<RouteData> getRoutes()
public Map<Class<? extends RouterLayout>,List<RouteData>> getRoutesByParent()
public static String resolve(Class<?> component, Route route)
component
- the component where the route points toroute
- the annotationCopyright © 2018. All rights reserved.