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

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

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