From a0912d4767592d829c57ba3b8c6ada818096e878 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 6 Jun 2023 22:33:26 +0800 Subject: [PATCH] duplicate layout --- pages/index.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pages/index.js b/pages/index.js index 6aa7fc52..94334aef 100644 --- a/pages/index.js +++ b/pages/index.js @@ -5,7 +5,8 @@ import { useGlobal } from '@/lib/global' import { generateRss } from '@/lib/rss' import { generateRobotsTxt } from '@/lib/robots.txt' import dynamic from 'next/dynamic' -import { useEffect, useState } from 'react' +import { Suspense, useEffect, useState } from 'react' +import Loading from '@/components/Loading' /** * 懒加载默认主题 @@ -26,16 +27,26 @@ const Index = props => { useEffect(() => { const loadLayout = async () => { - const NewLayoutIndex = dynamic(() => import(`@/themes/${theme}`).then(async (m) => { - setOnReading(false) - return m.LayoutIndex - }), { ssr: true }) - setLayoutIndex(NewLayoutIndex) + try { + const NewLayoutIndex = await dynamic(() => import(`@/themes/${theme}`).then(async (m) => { + setOnReading(false) + return m.LayoutIndex + })) + + setLayoutIndex(NewLayoutIndex) + } catch (error) { + console.error('Error while loading layout:', error) + } } + loadLayout() }, [theme]) - return + return ( + }> + + + ) } /**