Skip to content

Commit

Permalink
feat: link component internal url test should include hash routes (#147
Browse files Browse the repository at this point in the history
…) (#148)

Co-authored-by: Fran McDade <[email protected]>
  • Loading branch information
frano-m and Fran McDade authored Aug 7, 2024
1 parent 2f453dd commit a797199
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Links/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Url, UrlObjectWithHrefAndQuery } from "./entities";
* @returns true if the given link is an internal link.
*/
export function isClientSideNavigation(link: string): boolean {
return /^\/(?!\/)/.test(link);
return /^\/(?!\/)|^#/.test(link);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/components/Links/components/Link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const Link = ({
target,
TypographyProps,
url,
...props /* Spread props to allow for specific MuiLink prop overrides. */
}: LinkProps): JSX.Element => {
if (isURLObjectWithHrefAndQuery(url)) {
/* Internal navigation - explore link */
Expand All @@ -62,6 +63,7 @@ export const Link = ({
target={target || ANCHOR_TARGET.SELF}
onClick={onClick}
{...TypographyProps}
{...props}
>
{label}
</MLink>
Expand All @@ -82,6 +84,7 @@ export const Link = ({
rel={REL_ATTRIBUTE.NO_OPENER_NO_REFERRER}
target={target || ANCHOR_TARGET.BLANK}
{...TypographyProps}
{...props}
>
{label}
</MLink>
Expand All @@ -92,7 +95,12 @@ export const Link = ({
}
/* Invalid URL */
return (
<MTypography component="span" variant="inherit" {...TypographyProps}>
<MTypography
component="span"
variant="inherit"
{...TypographyProps}
{...props}
>
{label}
</MTypography>
);
Expand Down

0 comments on commit a797199

Please sign in to comment.