Skip to content

Commit

Permalink
πŸ› Fix bug with internal urls #1919
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolucchesi committed Oct 5, 2023
1 parent 749cacd commit dd3f8ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/pageComponents/shared/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import NextLink, { LinkProps } from 'next/link'
import { getUrlFromAction } from '../../common/helpers/getUrlFromAction'
import { getLocaleFromName } from '../../lib/localization'
import type { LinkData } from '../../types/types'
import { cloneElement } from 'react'

type Props = {
action: LinkData
children?: React.ReactNode
children?: React.ReactElement
} & (ButtonLinkProps | LinkProps)

export const ButtonLink = ({ action, children, ...rest }: Props) => {
Expand All @@ -21,9 +22,10 @@ export const ButtonLink = ({ action, children, ...rest }: Props) => {
// If the URL is a static AEM page it should behave as an internal link in the web
if (type === 'internalUrl') {
const locale = getLocaleFromName(action.link?.lang)
const child = children ? cloneElement(children, { href: url, locale: locale, ariaLabel: ariaLabel }) : undefined
return (
<>
{children || (
{child || (
<Link locale={locale} href={url} aria-label={ariaLabel} {...(rest as ButtonLinkProps)}>
{label}
</Link>
Expand Down

0 comments on commit dd3f8ad

Please sign in to comment.