Browse Source

use next/link and navigate to /permalink

yohei0125 3 years ago
parent
commit
ac0a421ba8
1 changed files with 11 additions and 4 deletions
  1. 11 4
      packages/app/src/components/PageAlert/OldRevisionAlert.tsx

+ 11 - 4
packages/app/src/components/PageAlert/OldRevisionAlert.tsx

@@ -1,20 +1,27 @@
 import React from 'react';
 import React from 'react';
+
+import Link from 'next/link';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
+
 import { useIsLatestRevision } from '~/stores/context';
 import { useIsLatestRevision } from '~/stores/context';
+import { useSWRxCurrentPage } from '~/stores/page';
 
 
 export const OldRevisionAlert = (): JSX.Element => {
 export const OldRevisionAlert = (): JSX.Element => {
 
 
-  const { t } = useTranslation()
+  const { t } = useTranslation();
   const { data: isLatestRevision } = useIsLatestRevision();
   const { data: isLatestRevision } = useIsLatestRevision();
+  const { data: page } = useSWRxCurrentPage();
 
 
-  if (isLatestRevision == null || isLatestRevision) {
-    return <></>
+  if (page == null || isLatestRevision == null || isLatestRevision) {
+    return <></>;
   }
   }
 
 
   return (
   return (
     <div className="alert alert-warning">
     <div className="alert alert-warning">
       <strong>{ t('Warning') }: </strong> { t('page_page.notice.version') }
       <strong>{ t('Warning') }: </strong> { t('page_page.notice.version') }
-      <a href="{ encodeURI(page.path) }"><i className="icon-fw icon-arrow-right-circle"></i>{ t('Show latest') }</a>
+      <Link href={encodeURI(page._id)}>
+        <a><i className="icon-fw icon-arrow-right-circle"></i>{ t('Show latest') }</a>
+      </Link>
     </div>
     </div>
   );
   );
 };
 };