Add auto set title to AuthRoute

This commit is contained in:
2023-10-11 14:04:33 +08:00
parent 3d84a8eed4
commit 885a097e7f
2 changed files with 16 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { getLoginStatus } from '@/utils/auth.ts'
import { PRODUCTION_NAME } from '@/constants/Common.constants.ts'
const AuthRoute = () => {
const matches = useMatches()
@@ -8,6 +9,9 @@ const AuthRoute = () => {
const isLogin = getLoginStatus()
return useMemo(() => {
document.title = `${handle?.titlePrefix ?? ''}${
handle?.title ? handle?.title : PRODUCTION_NAME
}${handle?.titlePostfix ?? ''}`
if (handle?.auth && !isLogin) {
return <Navigate to="/login" />
}
@@ -15,7 +19,15 @@ const AuthRoute = () => {
return <Navigate to="/" />
}
return outlet
}, [handle?.auth, isLogin, lastMatch.pathname, outlet])
}, [
handle?.auth,
handle?.title,
handle?.titlePostfix,
handle?.titlePrefix,
isLogin,
lastMatch.pathname,
outlet
])
}
export default AuthRoute

3
src/vite-env.d.ts vendored
View File

@@ -13,6 +13,9 @@ type RouteHandle = {
name?: string
menu?: boolean
auth?: boolean
titlePrefix?: string
title?: string
titlePostfix?: string
}
type _Response<T> = {