com.vaadin.flow.router.
Class RouterLink
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.router.RouterLink
-
All Implemented Interfaces:
AttachNotifier
,BlurNotifier<RouterLink>
,DetachNotifier
,Focusable<RouterLink>
,FocusNotifier<RouterLink>
,HasComponents
,HasElement
,HasEnabled
,HasStyle
,HasText
,AfterNavigationObserver
,AfterNavigationHandler
,Serializable
@Tag("a") public class RouterLink extends Component implements HasText, HasComponents, HasStyle, AfterNavigationObserver, Focusable<RouterLink>
A link that handles navigation internally using
Router
instead of loading a new page in the browser.The
href
attribute ofComponent.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.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace
-
-
Constructor Summary
Constructors Constructor Description RouterLink()
Creates a new empty router link.
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(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
All Methods Modifier and Type Method Description void
afterNavigation(AfterNavigationEvent event)
Callback executed after navigation has been executed.
HighlightAction<RouterLink>
getHighlightAction()
Gets the
HighlightAction
of this link.HighlightCondition<RouterLink>
getHighlightCondition()
Gets the
HighlightCondition
of this link.String
getHref()
Gets the href (the URL) of this link.
Optional<QueryParameters>
getQueryParameters()
Gets the
QueryParameters
of this link.void
setHighlightAction(HighlightAction<RouterLink> highlightAction)
Sets the
HighlightAction
of this link, which will be performed with the evaluation of this link'sHighlightCondition
.void
setHighlightCondition(HighlightCondition<RouterLink> highlightCondition)
Sets the
HighlightCondition
of this link, which determines if the link should be highlighted when aAfterNavigationEvent
occurs.void
setQueryParameters(QueryParameters queryParameters)
Sets the
QueryParameters
of this link.<T,C extends Component & HasUrlParameter<T>>
voidsetRoute(Router router, Class<? extends C> navigationTarget, T parameter)
Set the navigation target for this link.
void
setRoute(Router router, Class<? extends Component> navigationTarget)
Set the navigation target for this link.
void
setRoute(Router router, Class<? extends Component> navigationTarget, RouteParameters parameters)
Set the navigation target for this link.
<T,C extends Component & HasUrlParameter<T>>
voidsetRoute(Class<? extends C> navigationTarget, T parameter)
Set the navigation target for this link.
void
setRoute(Class<? extends Component> navigationTarget)
Set the navigation target for this link.
void
setRoute(Class<? extends Component> navigationTarget, RouteParameters parameters)
Set the navigation target for this link.
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
-
-
-
Constructor Detail
-
RouterLink
public RouterLink()
Creates a new empty router link.
-
RouterLink
public RouterLink(String text, Class<? extends Component> navigationTarget)
Creates a new router link for the given navigation target using the given text.
Parameters:
text
- link textnavigationTarget
- navigation target
-
RouterLink
public 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.
Type Parameters:
T
- url parameter typeC
- navigation target typeParameters:
text
- link textnavigationTarget
- navigation targetparameter
- url parameter for navigation target
-
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
-
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 targetThrows:
IllegalArgumentException
- if navigation target requires parameters
-
RouterLink
public 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.
Type Parameters:
T
- url parameter typeC
- navigation target typeParameters:
router
- router used for navigationtext
- link textnavigationTarget
- navigation targetparameter
- url parameter for navigation target
-
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
-
-
Method Detail
-
setRoute
public void setRoute(Router router, Class<? extends Component> navigationTarget)
Set the navigation target for this link.
Parameters:
router
- router used for navigationnavigationTarget
- navigation targetThrows:
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 typeParameters:
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
-
setRoute
public void setRoute(Class<? extends Component> navigationTarget)
Set the navigation target for this link.
Parameters:
navigationTarget
- navigation targetThrows:
IllegalArgumentException
- if navigation target requires parameters
-
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 typeParameters:
navigationTarget
- navigation targetparameter
- url parameter for navigation target
-
setRoute
public void setRoute(Class<? extends Component> navigationTarget, RouteParameters parameters)
Set the navigation target for this link.
Parameters:
navigationTarget
- navigation targetparameters
- route parameters for navigation target
-
getHref
public String getHref()
Gets the href (the URL) of this link.
Returns:
the href
-
getQueryParameters
public Optional<QueryParameters> getQueryParameters()
Gets the
QueryParameters
of this link.Returns:
an optional of
QueryParameters
, or an empty optional if there are no query parameters setSee Also:
-
setQueryParameters
public void setQueryParameters(QueryParameters queryParameters)
Sets the
QueryParameters
of this link.The query string will be generated from
QueryParameters.getQueryString()
and will be appended to thehref
attribute of this link.Parameters:
queryParameters
- the query parameters object, ornull
to remove existing query parameters
-
getHighlightCondition
public HighlightCondition<RouterLink> getHighlightCondition()
Gets the
HighlightCondition
of 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
public void setHighlightCondition(HighlightCondition<RouterLink> highlightCondition)
Sets the
HighlightCondition
of this link, which determines if the link should be highlighted when aAfterNavigationEvent
occurs.The evaluation of this condition will be processed by this link's
HighlightAction
.Parameters:
highlightCondition
- the highlight condition, notnull
See Also:
-
getHighlightAction
public HighlightAction<RouterLink> getHighlightAction()
Gets the
HighlightAction
of this link.The default action is to toggle the
highlight
attribute of the element, as defined inHighlightActions.toggleAttribute(String)
.Returns:
the highlight action, never
null
See Also:
-
setHighlightAction
public void setHighlightAction(HighlightAction<RouterLink> highlightAction)
Sets the
HighlightAction
of this link, which will be performed with the evaluation of this link'sHighlightCondition
.The old action will be executed passing
false
toHighlightAction.highlight(Object, boolean)
to clear any previous highlight state.Parameters:
highlightAction
- the highlight action, notnull
See Also:
-
afterNavigation
public void afterNavigation(AfterNavigationEvent event)
Description copied from interface:
AfterNavigationHandler
Callback executed after navigation has been executed.
Specified by:
afterNavigation
in interfaceAfterNavigationHandler
Parameters:
event
- after navigation event with event details
-
-