From 8bf3070022cea6f7f6ab530327c7eed717a27c7d Mon Sep 17 00:00:00 2001 From: Yngrid Coello Date: Mon, 18 Dec 2023 16:52:13 +0100 Subject: [PATCH] CR changes --- packages/kbn-router-utils/README.md | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/kbn-router-utils/README.md b/packages/kbn-router-utils/README.md index 970fea12dbb4e..e5dcb4cdb4fe4 100644 --- a/packages/kbn-router-utils/README.md +++ b/packages/kbn-router-utils/README.md @@ -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 ( + <> + + {discoverLinkTitle} + + + ); +}; +```