Add auto set title to AuthRoute
This commit is contained in:
@@ -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
3
src/vite-env.d.ts
vendored
@@ -13,6 +13,9 @@ type RouteHandle = {
|
||||
name?: string
|
||||
menu?: boolean
|
||||
auth?: boolean
|
||||
titlePrefix?: string
|
||||
title?: string
|
||||
titlePostfix?: string
|
||||
}
|
||||
|
||||
type _Response<T> = {
|
||||
|
||||
Reference in New Issue
Block a user