feat: 添加pageTitle路由守卫,支持动态修改页面title

This commit is contained in:
张传龙 2022-03-24 20:47:05 +08:00
parent 396428104a
commit 51a583fc1e
2 changed files with 14 additions and 0 deletions

View File

@ -1,7 +1,9 @@
import { createPageLoadingGuard } from './pageLoadingGuard' import { createPageLoadingGuard } from './pageLoadingGuard'
import { createPageTitleGuard } from './pageTitleGuard'
import { createPermissionGuard } from './permissionGuard' import { createPermissionGuard } from './permissionGuard'
export function setupRouterGuard(router) { export function setupRouterGuard(router) {
createPageLoadingGuard(router) createPageLoadingGuard(router)
createPermissionGuard(router) createPermissionGuard(router)
createPageTitleGuard(router)
} }

View File

@ -0,0 +1,12 @@
const baseTitle = import.meta.env.VITE_APP_TITLE
export function createPageTitleGuard(router) {
router.afterEach((to) => {
const pageTitle = to.meta?.title
if (pageTitle) {
document.title = `${pageTitle} | ${baseTitle}`
} else {
document.title = baseTitle
}
})
}