Skip to content

Commit

Permalink
fix: local path regex
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 15, 2020
1 parent 597dcc0 commit a78ef69
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ui/app-components/src/Link/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { FC } from 'react';
import React, { FC, useMemo } from 'react';
import { LinkProps } from 'theme-ui';
import { ExternalLink } from '@component-controls/components';
import { useGetLinkClass } from './LinkContext';
export const Link: FC<LinkProps> = props => {
const { href } = props;
if (typeof href === 'string' && !/\/$/.test(href)) {
//https://stackoverflow.com/questions/10687099/how-to-test-if-a-url-string-is-absolute-or-relative/10687158
const r = useMemo(() => new RegExp('^(?:[a-z]+:)?//', 'i'), []);
if (typeof href === 'string' && r.test(href)) {
//@ts-ignore
return <ExternalLink {...props} />;
}
Expand Down

0 comments on commit a78ef69

Please sign in to comment.