Skip to content

Commit

Permalink
no basePath for external links
Browse files Browse the repository at this point in the history
  • Loading branch information
upreeti committed Dec 16, 2024
1 parent da89d17 commit 739eeec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ui/link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const Link = forwardRef<HTMLButtonElement | HTMLAnchorElement, LinkProps>(
)) ||
''
: to;
const IS_EXTERNAL_LINK_REGEX = /^(?:(http|https):\/\/)/;
const staticBasePath =
href != null || typeof to === 'string' ? routeAttributes.basePath : '';
(href != null && !IS_EXTERNAL_LINK_REGEX.test(href)) || typeof to === 'string' ? routeAttributes.basePath : '';

Check warning on line 77 in src/ui/link/index.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Replace `·typeof·to·===·'string'·?·routeAttributes.basePath` with `⏎······typeof·to·===·'string'⏎········?·routeAttributes.basePath⏎·······`

const triggerPrefetch = useCallback(() => {
// ignore if async route not ready yet
Expand Down
16 changes: 15 additions & 1 deletion src/ui/link/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('<Link />', () => {
);
});

it('should push history with correct link for href when given basePath', () => {
it('should push history with correct link for relative href when given basePath', () => {
renderInRouter(
'my link',
{
Expand All @@ -105,6 +105,20 @@ describe('<Link />', () => {
);
});

it('should not add basePath for external links', () => {
renderInRouter(
'my link',
{
href: 'https://www.atlassian.com/',
},
'/base'
);
expect(screen.getByRole('link', { name: 'my link' })).toHaveAttribute(
'href',
'https://www.atlassian.com/'
);
});

it('should pass props to the child element', () => {
renderInRouter('my link', {
...defaultProps,
Expand Down

0 comments on commit 739eeec

Please sign in to comment.