@Tag(value="a") public class RouterLink extends Component implements HasText, HasComponents, HasStyle, AfterNavigationObserver
Router
instead of
loading a new page in the browser.
The href
attribute of Component.getElement()
will only be
up-to-date when the component is attached to a UI.
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.
|
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's HighlightCondition . |
void |
setHighlightCondition(HighlightCondition<RouterLink> highlightCondition)
Sets the
HighlightCondition of this link, which determines if the
link should be highlighted when a AfterNavigationEvent occurs. |
void |
setQueryParameters(QueryParameters queryParameters)
Sets the
QueryParameters of this link. |
<T,C extends Component & HasUrlParameter<T>> |
setRoute(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.
|
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
add, add, addComponentAsFirst, addComponentAtIndex, remove, removeAll
isEnabled, setEnabled
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addAttachListener
addDetachListener
public RouterLink()
public RouterLink(String text, Class<? extends Component> navigationTarget)
text
- link textnavigationTarget
- navigation targetpublic RouterLink(String text, Class<? extends C> navigationTarget, T parameter)
T
- url parameter typeC
- navigation target typetext
- link textnavigationTarget
- navigation targetparameter
- url parameter for navigation targetpublic RouterLink(Router router, String text, Class<? extends Component> navigationTarget)
router
- router used for navigationtext
- link textnavigationTarget
- navigation targetpublic RouterLink(Router router, String text, Class<? extends C> navigationTarget, T parameter)
T
- url parameter typeC
- navigation target typerouter
- router used for navigationtext
- link textnavigationTarget
- navigation targetparameter
- url parameter for navigation targetpublic void setRoute(Router router, Class<? extends Component> navigationTarget)
router
- router used for navigationnavigationTarget
- navigation targetpublic <T,C extends Component & HasUrlParameter<T>> void setRoute(Router router, Class<? extends C> navigationTarget, T parameter)
T
- url parameter typeC
- navigation target typerouter
- router used for navigationnavigationTarget
- navigation targetparameter
- url parameter for navigation targetpublic String getHref()
public Optional<QueryParameters> getQueryParameters()
QueryParameters
of this link.QueryParameters
, or an empty optional if
there are no query parameters setsetQueryParameters(QueryParameters)
public void setQueryParameters(QueryParameters queryParameters)
QueryParameters
of this link.
The query string will be generated from
QueryParameters.getQueryString()
and will be appended to the
href
attribute of this link.
queryParameters
- the query parameters object, or null
to remove
existing query parameterspublic HighlightCondition<RouterLink> getHighlightCondition()
HighlightCondition
of this link.
The default condition is to checked whether the current location starts
with this link's getHref()
value, as defined in
HighlightConditions.locationPrefix()
.
null
setHighlightCondition(HighlightCondition)
public void setHighlightCondition(HighlightCondition<RouterLink> highlightCondition)
HighlightCondition
of this link, which determines if the
link should be highlighted when a AfterNavigationEvent
occurs.
The evaluation of this condition will be processed by this link's
HighlightAction
.
highlightCondition
- the highlight condition, not null
setHighlightAction(HighlightAction)
,
HighlightConditions
public HighlightAction<RouterLink> getHighlightAction()
HighlightAction
of this link.
The default action is to toggle the highlight
attribute of the
element, as defined in HighlightActions.toggleAttribute(String)
.
null
setHighlightAction(HighlightAction)
public void setHighlightAction(HighlightAction<RouterLink> highlightAction)
HighlightAction
of this link, which will be performed
with the evaluation of this link's HighlightCondition
.
The old action will be executed passing false
to
HighlightAction.highlight(Object, boolean)
to clear any previous
highlight state.
highlightAction
- the highlight action, not null
setHighlightCondition(HighlightCondition)
,
HighlightActions
public void afterNavigation(AfterNavigationEvent event)
AfterNavigationHandler
afterNavigation
in interface AfterNavigationHandler
event
- after navigation event with event detailsCopyright © 2019. All rights reserved.