未登录系统不渲染Outlet,避免有无效请求

dev/timezone
Jimmy Liow 1 year ago
parent 831e62ae9b
commit b8f63a3a26

@ -2,10 +2,10 @@ import ErrorBoundary from '@/components/ErrorBoundary'
import useAuthStore from '@/stores/AuthStore' import useAuthStore from '@/stores/AuthStore'
import useConversationStore from '@/stores/ConversationStore' import useConversationStore from '@/stores/ConversationStore'
import { useThemeContext } from '@/stores/ThemeContext' import { useThemeContext } from '@/stores/ThemeContext'
import { App as AntApp, ConfigProvider, Empty, Layout, Typography, theme } from 'antd' import { App as AntApp, ConfigProvider, Empty, theme } from 'antd'
import zhLocale from 'antd/locale/zh_CN' import zhLocale from 'antd/locale/zh_CN'
import 'dayjs/locale/zh-cn' import 'dayjs/locale/zh-cn'
import { useEffect, useState } from 'react' import { useEffect } from 'react'
import { Outlet, useHref, useNavigate } from 'react-router-dom' import { Outlet, useHref, useNavigate } from 'react-router-dom'
import AppLogo from '@/assets/highlights_travel_300_300.png' import AppLogo from '@/assets/highlights_travel_300_300.png'
@ -41,17 +41,15 @@ function AuthApp() {
}; };
}, []) }, [])
// /p...
const needToLogin = (loginUser.userId === -1) && (href.indexOf('/p/') === -1)
useEffect(() => { useEffect(() => {
// /p... if (needToLogin) {
if ((loginUser.userId === -1) && (href.indexOf('/p/') === -1)) {
navigate('/p/dingding/login?origin_url=' + href) navigate('/p/dingding/login?origin_url=' + href)
} }
}, [href]) }, [href])
const {
token: { colorBgContainer },
} = theme.useToken()
return ( return (
<ConfigProvider <ConfigProvider
theme={{ theme={{
@ -67,7 +65,7 @@ function AuthApp() {
renderEmpty={() => <Empty description={false} />}> renderEmpty={() => <Empty description={false} />}>
<AntApp> <AntApp>
<ErrorBoundary> <ErrorBoundary>
<Outlet /> {needToLogin ? <>login...</> : <Outlet />}
<dialog id='about-dialog' className='border-0'> <dialog id='about-dialog' className='border-0'>
<img className='logo' src={AppLogo} alt='logo' /> <img className='logo' src={AppLogo} alt='logo' />
<section className='about'> <section className='about'>

Loading…
Cancel
Save