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