Class RouterLink
- All Implemented Interfaces:
AttachNotifier,BlurNotifier<RouterLink>,DetachNotifier,Focusable<RouterLink>,FocusNotifier<RouterLink>,HasComponents,HasComponentsOfType<Component>,HasElement,HasEnabled,HasStyle,HasText,AfterNavigationObserver,AfterNavigationHandler,Serializable
Router instead of
loading a new page in the browser. setOpenInNewBrowserTab(boolean)
opens the route in a new browser tab instead.
The href attribute of Component.getElement() will only be
up-to-date when the component is attached to a UI.
- Since:
- 1.0
- Author:
- Vaadin Ltd
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.Focusable
Focusable.FocusJsNested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new empty router link.RouterLink(Router router, Class<? extends C> navigationTarget, T parameter) Creates a new router link for the given navigation target using the given parameter.RouterLink(Router router, Class<? extends Component> navigationTarget) Creates a new router link for the given navigation target.RouterLink(Router router, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given parameters.RouterLink(Router router, String text, Class<? extends C> navigationTarget, T parameter) Creates a new router link for the given navigation target using the given text and parameter.RouterLink(Router router, String text, Class<? extends Component> navigationTarget) Creates a new router link for the given navigation target using the given text.RouterLink(Router router, String text, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given text and parameters.RouterLink(Class<? extends C> navigationTarget, T parameter) Creates a new router link for the given navigation target using the given parameter.RouterLink(Class<? extends Component> navigationTarget) Creates a new router link for the given navigation target.RouterLink(Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given parameters.RouterLink(String text, Class<? extends C> navigationTarget, T parameter) Creates a new router link for the given navigation target using the given text and parameter.RouterLink(String text, Class<? extends Component> navigationTarget) Creates a new router link for the given navigation target using the given text.RouterLink(String text, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given text and parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidCallback executed after navigation has been executed.Gets theHighlightActionof this link.Gets theHighlightConditionof this link.getHref()Gets the href (the URL) of this link.Gets theQueryParametersof this link.Gets the browsing context the link opens in.booleanGets whether the link opens its route in a new browser tab.voidsetHighlightAction(HighlightAction<RouterLink> highlightAction) Sets theHighlightActionof this link, which will be performed with the evaluation of this link'sHighlightCondition.voidsetHighlightCondition(HighlightCondition<RouterLink> highlightCondition) Sets theHighlightConditionof this link, which determines if the link should be highlighted when aAfterNavigationEventoccurs.voidsetOpenInNewBrowserTab(boolean openInNewBrowserTab) Sets whether the link opens its route in a new browser tab, through the_blanktarget.voidsetQueryParameters(QueryParameters queryParameters) Sets theQueryParametersof this link.<T,C extends Component & HasUrlParameter<T>>
voidSet the navigation target for this link.voidSet the navigation target for this link.voidsetRoute(Router router, Class<? extends Component> navigationTarget, RouteParameters parameters) Set the navigation target for this link.<T,C extends Component & HasUrlParameter<T>>
voidSet the navigation target for this link.voidSet the navigation target for this link.voidsetRoute(Class<? extends Component> navigationTarget, RouteParameters parameters) Set the navigation target for this link.voidSets the browsing context the link opens in, as thetargetattribute of the<a>element.Methods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, add, addComponentAsFirst, addComponentAtIndex, bindChildren, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replaceMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
bindText, getText, getWhiteSpace, setText, setWhiteSpace
-
Constructor Details
-
RouterLink
public RouterLink()Creates a new empty router link. -
RouterLink
Creates a new router link for the given navigation target.- Parameters:
navigationTarget- navigation target- Since:
- 23.2
-
RouterLink
Creates a new router link for the given navigation target using the given text.- Parameters:
text- link textnavigationTarget- navigation target
-
RouterLink
Creates a new router link for the given navigation target using the given parameter.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
navigationTarget- navigation targetparameter- url parameter for navigation target- Since:
- 23.2
-
RouterLink
Creates a new router link for the given navigation target using the given text and parameter.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
text- link textnavigationTarget- navigation targetparameter- url parameter for navigation target
-
RouterLink
Creates a new router link for the given navigation target using the given parameters.- Parameters:
navigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 23.2
-
RouterLink
public RouterLink(String text, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given text and parameters.- Parameters:
text- link textnavigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 4.0
-
RouterLink
public RouterLink(Router router, Class<? extends Component> navigationTarget) throws IllegalArgumentException Creates a new router link for the given navigation target.- Parameters:
router- router used for navigationnavigationTarget- navigation target- Throws:
IllegalArgumentException- if navigation target requires parameters- Since:
- 23.2
-
RouterLink
public RouterLink(Router router, String text, Class<? extends Component> navigationTarget) throws IllegalArgumentException Creates a new router link for the given navigation target using the given text.- Parameters:
router- router used for navigationtext- link textnavigationTarget- navigation target- Throws:
IllegalArgumentException- if navigation target requires parameters
-
RouterLink
Creates a new router link for the given navigation target using the given parameter.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
router- router used for navigationnavigationTarget- navigation targetparameter- url parameter for navigation target- Since:
- 23.2
-
RouterLink
Creates a new router link for the given navigation target using the given text and parameter.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
router- router used for navigationtext- link textnavigationTarget- navigation targetparameter- url parameter for navigation target
-
RouterLink
public RouterLink(Router router, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given parameters.- Parameters:
router- router used for navigationnavigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 23.2
-
RouterLink
public RouterLink(Router router, String text, Class<? extends Component> navigationTarget, RouteParameters parameters) Creates a new router link for the given navigation target using the given text and parameters.- Parameters:
router- router used for navigationtext- link textnavigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 4.0
-
-
Method Details
-
setRoute
Set the navigation target for this link.- Parameters:
router- router used for navigationnavigationTarget- navigation target- Throws:
IllegalArgumentException- if navigation target requires parameters
-
setRoute
public <T,C extends Component & HasUrlParameter<T>> void setRoute(Router router, Class<? extends C> navigationTarget, T parameter) Set the navigation target for this link.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
router- router used for navigationnavigationTarget- navigation targetparameter- url parameter for navigation target
-
setRoute
public void setRoute(Router router, Class<? extends Component> navigationTarget, RouteParameters parameters) Set the navigation target for this link.- Parameters:
router- router used for navigationnavigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 4.0
-
setRoute
Set the navigation target for this link.- Parameters:
navigationTarget- navigation target- Throws:
IllegalArgumentException- if navigation target requires parameters- Since:
- 2.1
-
setRoute
public <T,C extends Component & HasUrlParameter<T>> void setRoute(Class<? extends C> navigationTarget, T parameter) Set the navigation target for this link.- Type Parameters:
T- url parameter typeC- navigation target type- Parameters:
navigationTarget- navigation targetparameter- url parameter for navigation target- Since:
- 2.1
-
setRoute
Set the navigation target for this link.- Parameters:
navigationTarget- navigation targetparameters- route parameters for navigation target- Since:
- 4.0
-
getHref
Gets the href (the URL) of this link.- Returns:
- the href
-
getQueryParameters
Gets theQueryParametersof this link.- Returns:
- an optional of
QueryParameters, or an empty optional if there are no query parameters set - See Also:
-
setQueryParameters
Sets theQueryParametersof this link.The query string will be generated from
QueryParameters.getQueryString()and will be appended to thehrefattribute of this link.- Parameters:
queryParameters- the query parameters object, ornullto remove existing query parameters
-
setTarget
Sets the browsing context the link opens in, as thetargetattribute of the<a>element. Any target other than_selfleaves the click to the browser: the route opens in that context through a regular page load, with a UI of its own, and the current UI does not navigate.RouterLink link = new RouterLink("Report", ReportView.class); link.setTarget("_blank"); // same as setOpenInNewBrowserTab(true)- Parameters:
target- awindow.nameor one of_self,_blank,_parent,_top;nullor""removes the attribute, which opens the link in the current context- See Also:
-
getTarget
Gets the browsing context the link opens in.- Returns:
- the
targetattribute, ornullif none is set - See Also:
-
setOpenInNewBrowserTab
public void setOpenInNewBrowserTab(boolean openInNewBrowserTab) Sets whether the link opens its route in a new browser tab, through the_blanktarget. Turning it off removes the target, whatever it was.- Parameters:
openInNewBrowserTab-trueto open the route in a new tab,falseto navigate in the current one- See Also:
-
isOpenInNewBrowserTab
public boolean isOpenInNewBrowserTab()Gets whether the link opens its route in a new browser tab.- Returns:
trueif the target is_blank- See Also:
-
getHighlightCondition
Gets theHighlightConditionof this link.The default condition is to checked whether the current location starts with this link's
getHref()value, as defined inHighlightConditions.locationPrefix().- Returns:
- the highlight condition, never
null - See Also:
-
setHighlightCondition
Sets theHighlightConditionof this link, which determines if the link should be highlighted when aAfterNavigationEventoccurs.The evaluation of this condition will be processed by this link's
HighlightAction.- Parameters:
highlightCondition- the highlight condition, notnull- See Also:
-
getHighlightAction
Gets theHighlightActionof this link.The default action is to toggle the
highlightattribute of the element, as defined inHighlightActions.toggleAttribute(String).- Returns:
- the highlight action, never
null - See Also:
-
setHighlightAction
Sets theHighlightActionof this link, which will be performed with the evaluation of this link'sHighlightCondition.The old action will be executed passing
falsetoHighlightAction.highlight(Object, boolean)to clear any previous highlight state.- Parameters:
highlightAction- the highlight action, notnull- See Also:
-