Fix AuthRoute
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { getLoginStatus } from '@/utils/auth.ts'
|
||||
|
||||
const AuthRoute = () => {
|
||||
const match = useMatches()[1]
|
||||
const handle = match.handle as RouteHandle
|
||||
const matches = useMatches()
|
||||
const lastMatch = matches.reduce((_, second) => second)
|
||||
const handle = lastMatch.handle as RouteHandle
|
||||
const outlet = useOutlet()
|
||||
const isLogin = getLoginStatus()
|
||||
|
||||
@@ -10,11 +11,11 @@ const AuthRoute = () => {
|
||||
if (handle?.auth && !isLogin) {
|
||||
return <Navigate to="/login" />
|
||||
}
|
||||
if (isLogin && match.pathname === '/login') {
|
||||
if (isLogin && lastMatch.pathname === '/login') {
|
||||
return <Navigate to="/" />
|
||||
}
|
||||
return outlet
|
||||
}, [handle?.auth, isLogin, match.pathname, outlet])
|
||||
}, [handle?.auth, isLogin, lastMatch.pathname, outlet])
|
||||
}
|
||||
|
||||
export default AuthRoute
|
||||
|
||||
Reference in New Issue
Block a user