2026-03-03 21:05:16 +08:00
|
|
|
import { Suspense, lazy, useLayoutEffect } from 'react'
|
2026-02-14 17:30:00 +08:00
|
|
|
import { Route, Switch, useLocation } from 'wouter'
|
2025-09-29 16:33:15 +08:00
|
|
|
|
2026-02-27 19:46:44 +08:00
|
|
|
import Footer from './components/Footer'
|
|
|
|
|
import Header from './components/Header'
|
2026-03-03 21:05:16 +08:00
|
|
|
import { useLanguage } from './i18n/context'
|
2026-02-27 20:42:24 +08:00
|
|
|
import HomePage from './pages/Home'
|
2026-03-03 21:05:16 +08:00
|
|
|
import DocsLayout from './pages/docs/Layout'
|
|
|
|
|
|
|
|
|
|
const DocsPages = lazy(() => import('./pages/docs/index'))
|
|
|
|
|
|
|
|
|
|
// Prefetch docs chunk during idle time so navigation feels instant
|
|
|
|
|
if (typeof requestIdleCallback !== 'undefined') {
|
|
|
|
|
requestIdleCallback(() => import('./pages/docs/index'))
|
|
|
|
|
}
|
2025-09-29 16:33:15 +08:00
|
|
|
|
2026-02-14 17:30:00 +08:00
|
|
|
function ScrollToTop() {
|
|
|
|
|
const [pathname] = useLocation()
|
|
|
|
|
useLayoutEffect(() => {
|
|
|
|
|
window.scrollTo(0, 0)
|
|
|
|
|
}, [pathname])
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 21:05:16 +08:00
|
|
|
function DocsLoadingFallback() {
|
|
|
|
|
const { isZh } = useLanguage()
|
|
|
|
|
return (
|
|
|
|
|
<DocsLayout>
|
|
|
|
|
<div className="flex items-center gap-3 py-12 text-gray-500 dark:text-gray-400">
|
|
|
|
|
<div className="w-5 h-5 border-2 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
|
|
|
|
{isZh ? '文档加载中...' : 'Loading documentation...'}
|
|
|
|
|
</div>
|
|
|
|
|
</DocsLayout>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-29 16:33:15 +08:00
|
|
|
export default function Router() {
|
|
|
|
|
return (
|
2026-02-27 20:42:24 +08:00
|
|
|
<div className="flex min-h-screen flex-col">
|
2026-02-27 19:46:44 +08:00
|
|
|
<Header />
|
|
|
|
|
<Suspense>
|
|
|
|
|
<ScrollToTop />
|
|
|
|
|
<Switch>
|
|
|
|
|
<Route path="/">
|
|
|
|
|
<main
|
|
|
|
|
id="main-content"
|
2026-02-27 20:42:24 +08:00
|
|
|
className="flex-1 bg-linear-to-br from-blue-50 to-purple-50 dark:from-gray-900 dark:to-gray-800"
|
2026-02-27 19:46:44 +08:00
|
|
|
>
|
2026-02-27 20:42:24 +08:00
|
|
|
<HomePage />
|
2026-02-27 19:46:44 +08:00
|
|
|
</main>
|
|
|
|
|
</Route>
|
2025-09-29 16:33:15 +08:00
|
|
|
|
2026-02-27 19:46:44 +08:00
|
|
|
<Route path="/docs" nest>
|
2026-02-27 20:42:24 +08:00
|
|
|
<div className="flex-1 bg-white dark:bg-gray-900">
|
2026-03-03 21:05:16 +08:00
|
|
|
<Suspense fallback={<DocsLoadingFallback />}>
|
|
|
|
|
<DocsPages />
|
|
|
|
|
</Suspense>
|
2026-02-27 19:46:44 +08:00
|
|
|
</div>
|
|
|
|
|
</Route>
|
2025-09-29 16:33:15 +08:00
|
|
|
|
2026-02-27 19:46:44 +08:00
|
|
|
<Route>
|
2026-02-27 20:42:24 +08:00
|
|
|
<div className="flex-1 bg-white dark:bg-gray-900 flex items-center justify-center">
|
2026-02-27 19:46:44 +08:00
|
|
|
<div className="text-center">
|
|
|
|
|
<h1 className="text-4xl font-bold mb-4 text-gray-900 dark:text-white">404</h1>
|
|
|
|
|
<p className="text-xl text-gray-600 dark:text-gray-300">Page not found</p>
|
|
|
|
|
</div>
|
2026-01-16 15:05:09 +08:00
|
|
|
</div>
|
2026-02-27 19:46:44 +08:00
|
|
|
</Route>
|
|
|
|
|
</Switch>
|
|
|
|
|
</Suspense>
|
|
|
|
|
<Footer />
|
2026-02-27 20:42:24 +08:00
|
|
|
</div>
|
2025-09-29 16:33:15 +08:00
|
|
|
)
|
|
|
|
|
}
|