diff --git a/web/src/App.js b/web/src/App.js index bf5b69c4..7119ef18 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -27,6 +27,7 @@ import OAuth2Callback from './components/OAuth2Callback.js'; import PersonalSetting from './components/PersonalSetting.js'; import Setup from './pages/Setup/index.js'; import SetupCheck from './components/SetupCheck'; +import AuthRedirect from './components/AuthRedirect'; const Home = lazy(() => import('./pages/Home')); const Detail = lazy(() => import('./pages/Detail')); @@ -138,7 +139,9 @@ function App() { path='/login' element={ } key={location.pathname}> - + + + } /> @@ -146,7 +149,9 @@ function App() { path='/register' element={ } key={location.pathname}> - + + + } /> diff --git a/web/src/components/AuthRedirect.js b/web/src/components/AuthRedirect.js new file mode 100644 index 00000000..d22c675d --- /dev/null +++ b/web/src/components/AuthRedirect.js @@ -0,0 +1,14 @@ +import React from 'react'; +import { Navigate } from 'react-router-dom'; + +const AuthRedirect = ({ children }) => { + const user = localStorage.getItem('user'); + + if (user) { + return ; + } + + return children; +}; + +export default AuthRedirect; \ No newline at end of file diff --git a/web/src/pages/Home/index.js b/web/src/pages/Home/index.js index 7c151467..e67a4ed7 100644 --- a/web/src/pages/Home/index.js +++ b/web/src/pages/Home/index.js @@ -94,7 +94,7 @@ const Home = () => { {/* 操作按钮 */}
- +