This commit is contained in:
2023-09-03 16:05:52 +08:00
commit c4211ddf7c
28 changed files with 1740 additions and 0 deletions

20
src/AuthRoute.tsx Normal file
View File

@@ -0,0 +1,20 @@
import { getLoginStatus } from '@/utils/auth.ts'
const AuthRoute = () => {
const match = useMatches()[1]
const handle = match.handle as RouteHandle
const outlet = useOutlet()
const isLogin = getLoginStatus()
return useMemo(() => {
if (handle?.auth && !isLogin) {
return <Navigate to="/login" />
}
if (isLogin && match.pathname === '/login') {
return <Navigate to="/" />
}
return outlet
}, [handle?.auth, isLogin, match.pathname, outlet])
}
export default AuthRoute