feat: 添加pageTitle路由守卫,支持动态修改页面title
This commit is contained in:
parent
396428104a
commit
51a583fc1e
@ -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)
|
||||||
}
|
}
|
||||||
|
12
src/router/guard/pageTitleGuard.js
Normal file
12
src/router/guard/pageTitleGuard.js
Normal 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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user