|
@@ -8,7 +8,7 @@ import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:components:NextLink');
|
|
const logger = loggerFactory('growi:components:NextLink');
|
|
|
|
|
|
|
|
-const isAnchorLink = (href: string): boolean => {
|
|
|
|
|
|
|
+const hasAnchorLink = (href: string): boolean => {
|
|
|
return href.toString().length > 0 && href[0] === '#';
|
|
return href.toString().length > 0 && href[0] === '#';
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -23,10 +23,6 @@ const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const isTargetSelf = (target: string | undefined): boolean => {
|
|
|
|
|
- return target === undefined || target === '_self';
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
const isCreatablePage = (href: string) => {
|
|
const isCreatablePage = (href: string) => {
|
|
|
try {
|
|
try {
|
|
|
const url = new URL(href, 'http://example.com');
|
|
const url = new URL(href, 'http://example.com');
|
|
@@ -61,13 +57,13 @@ export const NextLink = (props: Props): JSX.Element => {
|
|
|
Object.entries(rest).filter(([key]) => key.startsWith('data-')),
|
|
Object.entries(rest).filter(([key]) => key.startsWith('data-')),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- if (isExternalLink(href, siteUrl) || !isTargetSelf(target)) {
|
|
|
|
|
|
|
+ if (isExternalLink(href, siteUrl) || target === '_blank') {
|
|
|
return (
|
|
return (
|
|
|
<a
|
|
<a
|
|
|
id={id}
|
|
id={id}
|
|
|
href={href}
|
|
href={href}
|
|
|
className={className}
|
|
className={className}
|
|
|
- target={target ?? '_blank'}
|
|
|
|
|
|
|
+ target="_blank"
|
|
|
onClick={onClick}
|
|
onClick={onClick}
|
|
|
rel="noopener noreferrer"
|
|
rel="noopener noreferrer"
|
|
|
{...dataAttributes}
|
|
{...dataAttributes}
|
|
@@ -84,12 +80,13 @@ export const NextLink = (props: Props): JSX.Element => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// when href is an anchor link or not-creatable path
|
|
// when href is an anchor link or not-creatable path
|
|
|
- if (isAnchorLink(href) || !isCreatablePage(href)) {
|
|
|
|
|
|
|
+ if (hasAnchorLink(href) || !isCreatablePage(href) || target != null) {
|
|
|
return (
|
|
return (
|
|
|
<a
|
|
<a
|
|
|
id={id}
|
|
id={id}
|
|
|
href={href}
|
|
href={href}
|
|
|
className={className}
|
|
className={className}
|
|
|
|
|
+ target={target}
|
|
|
onClick={onClick}
|
|
onClick={onClick}
|
|
|
{...dataAttributes}
|
|
{...dataAttributes}
|
|
|
>
|
|
>
|