diff --git a/src/AuthRoute.tsx b/src/AuthRoute.tsx index 788ba52..57948cb 100644 --- a/src/AuthRoute.tsx +++ b/src/AuthRoute.tsx @@ -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 } - if (isLogin && match.pathname === '/login') { + if (isLogin && lastMatch.pathname === '/login') { return } return outlet - }, [handle?.auth, isLogin, match.pathname, outlet]) + }, [handle?.auth, isLogin, lastMatch.pathname, outlet]) } export default AuthRoute