com.vaadin.flow.router.
Class RouterLink
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.router.RouterLink
-
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasStyle, HasText, AfterNavigationObserver, AfterNavigationHandler, Serializable
@Tag(value="a") public class RouterLink extends Component implements HasText, HasComponents, HasStyle, AfterNavigationObserver
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:
-
-
Constructor Summary
Constructors Constructor and 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(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.
-
Method Summary
All Methods Modifier and Type Method and Description void
afterNavigation(AfterNavigationEvent event)
Method called 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.
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, 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.HasComponents
add, remove, removeAll
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
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.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
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(Router router, String text, Class<? extends Component> navigationTarget)
Creates a new router link for the given navigation target using the given text.
Parameters:
router
- router used for navigationtext
- link textnavigationTarget
- navigation target
-
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
-
-
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 target
-
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
-
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
Method called after navigation has been executed.
Specified by:
afterNavigation
in interfaceAfterNavigationHandler
Parameters:
event
- after navigation event with event details
-
-