Commit d85e25fc by CaIon

feat: Integrate SetupCheck component for improved setup validation in routing

parent 9dc851d6
...@@ -26,6 +26,7 @@ import Playground from './pages/Playground/Playground.js'; ...@@ -26,6 +26,7 @@ import Playground from './pages/Playground/Playground.js';
import OAuth2Callback from "./components/OAuth2Callback.js"; import OAuth2Callback from "./components/OAuth2Callback.js";
import PersonalSetting from './components/PersonalSetting.js'; import PersonalSetting from './components/PersonalSetting.js';
import Setup from './pages/Setup/index.js'; import Setup from './pages/Setup/index.js';
import SetupCheck from './components/SetupCheck';
const Home = lazy(() => import('./pages/Home')); const Home = lazy(() => import('./pages/Home'));
const Detail = lazy(() => import('./pages/Detail')); const Detail = lazy(() => import('./pages/Detail'));
...@@ -35,7 +36,7 @@ function App() { ...@@ -35,7 +36,7 @@ function App() {
const location = useLocation(); const location = useLocation();
return ( return (
<> <SetupCheck>
<Routes> <Routes>
<Route <Route
path='/' path='/'
...@@ -286,7 +287,7 @@ function App() { ...@@ -286,7 +287,7 @@ function App() {
/> />
<Route path='*' element={<NotFound />} /> <Route path='*' element={<NotFound />} />
</Routes> </Routes>
</> </SetupCheck>
); );
} }
......
import React, { useContext, useEffect } from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { StatusContext } from '../context/Status';
const SetupCheck = ({ children }) => {
const [statusState] = useContext(StatusContext);
const location = useLocation();
useEffect(() => {
if (statusState?.status?.setup === false && location.pathname !== '/setup') {
window.location.href = '/setup';
}
}, [statusState?.status?.setup, location.pathname]);
return children;
};
export default SetupCheck;
\ No newline at end of file
...@@ -66,13 +66,9 @@ const Home = () => { ...@@ -66,13 +66,9 @@ const Home = () => {
}; };
useEffect(() => { useEffect(() => {
if (statusState.status?.setup === false) {
window.location.href = '/setup';
return;
}
displayNotice().then(); displayNotice().then();
displayHomePageContent().then(); displayHomePageContent().then();
}); }, []);
return ( return (
<> <>
...@@ -116,6 +112,7 @@ const Home = () => { ...@@ -116,6 +112,7 @@ const Home = () => {
https://github.com/Calcium-Ion/new-api https://github.com/Calcium-Ion/new-api
</a> </a>
</p> </p>
<p> <p>
{t('协议')} {t('协议')}
<a <a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment