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
  • Loading branch information
Fran McDade authored and Fran McDade committed Aug 5, 2024
1 parent 812f430 commit bbbe7e3
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="noopener noreferrer"
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 bbbe7e3

Please sign in to comment.