Просмотр исходного кода

Pages that are not creatable will not be routed next

Shun Miyazawa 2 лет назад
Родитель
Сommit
3405eda3c3
1 измененных файлов с 16 добавлено и 0 удалено
  1. 16 0
      apps/app/src/components/ReactMarkdownComponents/NextLink.tsx

+ 16 - 0
apps/app/src/components/ReactMarkdownComponents/NextLink.tsx

@@ -1,3 +1,4 @@
+import { pagePathUtils } from '@growi/core';
 import Link, { LinkProps } from 'next/link';
 
 import { useSiteUrl } from '~/stores/context';
@@ -22,6 +23,13 @@ const isExternalLink = (href: string, siteUrl: string | undefined): boolean => {
   }
 };
 
+const isCreatablePage = (href: string) => {
+  const url = new URL(href);
+  const pathName = url.pathname;
+
+  return pagePathUtils.isCreatablePage(pathName);
+};
+
 type Props = Omit<LinkProps, 'href'> & {
   children: React.ReactNode,
   id?: string,
@@ -60,6 +68,14 @@ export const NextLink = (props: Props): JSX.Element => {
     );
   }
 
+  console.log(!isCreatablePage(href), href);
+
+  if (!isCreatablePage(href)) {
+    return (
+      <a href={href} className={className}>{children}</a>
+    );
+  }
+
   return (
     <Link {...rest} href={href} prefetch={false} legacyBehavior>
       <a href={href} className={className} {...dataAttributes}>{children}</a>