|
|
@@ -1,3 +1,4 @@
|
|
|
+import { pagePathUtils } from '@growi/core';
|
|
|
import Link, { LinkProps } from 'next/link';
|
|
|
|
|
|
import { useSiteUrl } from '~/stores/context';
|
|
|
@@ -22,6 +23,18 @@ const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const isCreatablePage = (href: string) => {
|
|
|
+ try {
|
|
|
+ const url = new URL(href);
|
|
|
+ const pathName = url.pathname;
|
|
|
+ return pagePathUtils.isCreatablePage(pathName);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.debug(err);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
type Props = Omit<LinkProps, 'href'> & {
|
|
|
children: React.ReactNode,
|
|
|
id?: string,
|
|
|
@@ -45,13 +58,6 @@ export const NextLink = (props: Props): JSX.Element => {
|
|
|
Object.entries(rest).filter(([key]) => key.startsWith('data-')),
|
|
|
);
|
|
|
|
|
|
- // when href is an anchor link
|
|
|
- if (isAnchorLink(href)) {
|
|
|
- return (
|
|
|
- <a id={id} href={href} className={className} {...dataAttributes}>{children}</a>
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
if (isExternalLink(href, siteUrl)) {
|
|
|
return (
|
|
|
<a id={id} href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
|
|
|
@@ -60,6 +66,13 @@ export const NextLink = (props: Props): JSX.Element => {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ // when href is an anchor link or not-creatable path
|
|
|
+ if (isAnchorLink(href) || !isCreatablePage(href)) {
|
|
|
+ return (
|
|
|
+ <a id={id} href={href} className={className} {...dataAttributes}>{children}</a>
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<Link {...rest} href={href} prefetch={false} legacyBehavior>
|
|
|
<a href={href} className={className} {...dataAttributes}>{children}</a>
|