From 51a583fc1e72de9fc597b58268159fcc4fbce5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BC=A0=E9=BE=99?= Date: Thu, 24 Mar 2022 20:47:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0pageTitle=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=AE=88=E5=8D=AB=EF=BC=8C=E6=94=AF=E6=8C=81=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/guard/index.js | 2 ++ src/router/guard/pageTitleGuard.js | 12 ++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/router/guard/pageTitleGuard.js diff --git a/src/router/guard/index.js b/src/router/guard/index.js index 519caa5..a8d88cd 100644 --- a/src/router/guard/index.js +++ b/src/router/guard/index.js @@ -1,7 +1,9 @@ import { createPageLoadingGuard } from './pageLoadingGuard' +import { createPageTitleGuard } from './pageTitleGuard' import { createPermissionGuard } from './permissionGuard' export function setupRouterGuard(router) { createPageLoadingGuard(router) createPermissionGuard(router) + createPageTitleGuard(router) } diff --git a/src/router/guard/pageTitleGuard.js b/src/router/guard/pageTitleGuard.js new file mode 100644 index 0000000..c26b7d2 --- /dev/null +++ b/src/router/guard/pageTitleGuard.js @@ -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 + } + }) +}