@@ -2,7 +2,6 @@ import { createBrowserRouter, Navigate } from 'react-router-dom'
|
|||||||
import { Layout } from './components/Layout'
|
import { Layout } from './components/Layout'
|
||||||
import { Screener } from './pages/Screener'
|
import { Screener } from './pages/Screener'
|
||||||
import { Financials } from './pages/Financials'
|
import { Financials } from './pages/Financials'
|
||||||
import { Onboarding } from './pages/Onboarding'
|
|
||||||
import { Auth } from './pages/Auth'
|
import { Auth } from './pages/Auth'
|
||||||
import { Data } from './pages/Data'
|
import { Data } from './pages/Data'
|
||||||
import { Monitor } from './pages/Monitor'
|
import { Monitor } from './pages/Monitor'
|
||||||
@@ -19,47 +18,11 @@ import { UserManage } from './pages/UserManage'
|
|||||||
import { Settings } from './pages/Settings'
|
import { Settings } from './pages/Settings'
|
||||||
import { Indices } from './pages/Indices'
|
import { Indices } from './pages/Indices'
|
||||||
import { Dev } from './pages/Dev'
|
import { Dev } from './pages/Dev'
|
||||||
import { useSettings } from './lib/useSharedQueries'
|
|
||||||
import { Logo } from './components/Logo'
|
|
||||||
|
|
||||||
// 首次使用守卫 —— 未完成向导则重定向到 /onboarding
|
|
||||||
// 只挂在根路由上;/onboarding 本身不被守卫,避免循环重定向。
|
|
||||||
// settings 由 Layout 预取,守卫判定不产生额外请求。
|
|
||||||
function OnboardingGuard({ children }: { children: React.ReactNode }) {
|
|
||||||
const settings = useSettings()
|
|
||||||
|
|
||||||
// 仅首次加载(本地无缓存)时显示占位。
|
|
||||||
// 后台重取 (isFetching) 时本地已有上一份缓存可用, 直接放行, 避免切页时整屏 logo 闪烁。
|
|
||||||
// 防误重定向已由 Onboarding/AI 等处 invalidate 前的 setQueryData 同步缓存兜底。
|
|
||||||
if (settings.isLoading) {
|
|
||||||
return (
|
|
||||||
<div className="min-h-screen bg-base grid place-items-center">
|
|
||||||
<div className="flex flex-col items-center gap-3 text-muted">
|
|
||||||
<Logo size={28} className="text-foreground" />
|
|
||||||
<div className="text-xs">加载中…</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询出错或字段缺失时不拦截 —— 宁可放行,也不把用户卡在空白页
|
|
||||||
if (settings.data && settings.data.onboarding_completed === false) {
|
|
||||||
return <Navigate to="/onboarding" replace />
|
|
||||||
}
|
|
||||||
|
|
||||||
return <>{children}</>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const router = createBrowserRouter([
|
export const router = createBrowserRouter([
|
||||||
{ path: '/onboarding', element: <Onboarding /> },
|
|
||||||
{ path: '/login', element: <Auth /> },
|
{ path: '/login', element: <Auth /> },
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
element: (
|
element: <Layout />,
|
||||||
<OnboardingGuard>
|
|
||||||
<Layout />
|
|
||||||
</OnboardingGuard>
|
|
||||||
),
|
|
||||||
children: [
|
children: [
|
||||||
{ index: true, element: <Dashboard /> },
|
{ index: true, element: <Dashboard /> },
|
||||||
{ path: 'overview', element: <Navigate to="/" replace /> },
|
{ path: 'overview', element: <Navigate to="/" replace /> },
|
||||||
|
|||||||
Reference in New Issue
Block a user