From 17c34d78f54e16ba45dfb4125054af4dfd7516cf Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 26 Apr 2022 10:43:35 +0800 Subject: [PATCH] =?UTF-8?q?404=E9=A1=B5=E9=9D=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/Layout404.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/themes/hexo/Layout404.js b/themes/hexo/Layout404.js index 6140c8fb..2bc61804 100644 --- a/themes/hexo/Layout404.js +++ b/themes/hexo/Layout404.js @@ -1,6 +1,22 @@ import LayoutBase from './LayoutBase' +import { useRouter } from 'next/router' +import { useEffect } from 'react' export const Layout404 = props => { + const router = useRouter() + useEffect(() => { + // 延时3秒如果加载失败就返回首页 + setTimeout(() => { + if (window) { + const article = document.getElementById('container') + if (!article) { + router.push('/').then(() => { + console.log('找不到页面', router.asPath) + }) + } + } + }, 3000) + }) return (