-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,34 @@ | ||
# @kbn/router-utils | ||
|
||
This package provides util functions when working with the router. | ||
|
||
## getRouterLinkProps | ||
|
||
Useful to generate link component properties for HTML elements, this link properties will allow them to behave as native links and handle events such as open in a new tab, or client-side navigation without refreshing the whole page. | ||
|
||
### Example | ||
|
||
We want a button to both navigate to Discover client-side or open on a new window. | ||
|
||
```ts | ||
const DiscoverLink = (discoverLinkParams) => { | ||
const discoverUrl = discover.locator?.getRedirectUrl(discoverLinkParams); | ||
|
||
const navigateToDiscover = () => { | ||
discover.locator?.navigate(discoverLinkParams); | ||
}; | ||
|
||
const linkProps = getRouterLinkProps({ | ||
href: discoverUrl, | ||
onClick: navigateToDiscover, | ||
}); | ||
|
||
return ( | ||
<> | ||
<EuiButton {...linkProps}> | ||
{discoverLinkTitle} | ||
</EuiButton> | ||
</> | ||
); | ||
}; | ||
``` |