From 3d84a8eed48b692c19e02c595133e20503410940 Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 11 Oct 2023 14:03:32 +0800 Subject: [PATCH] Fix AuthRoute --- src/AuthRoute.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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