Skip to content

Commit 2648fc4

Browse files
committed
feat: Set document title via route meta (#131)
1 parent 0820b7b commit 2648fc4

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const appName = 'vue3-vant-mobile'
2+
export const appDescription = 'An mobile web apps template based on the Vue 3 ecosystem'

src/router/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import 'nprogress/nprogress.css'
77
import type { EnhancedRouteLocation } from './types'
88
import useRouteCacheStore from '@/stores/modules/routeCache'
99
import { useUserStore } from '@/stores'
10+
1011
import { isLogin } from '@/utils/auth'
12+
import setPageTitle from '@/utils/set-page-title'
1113

1214
NProgress.configure({ showSpinner: true, parent: '#app' })
1315

@@ -30,6 +32,9 @@ router.beforeEach(async (to: EnhancedRouteLocation, _from, next) => {
3032
// Route cache
3133
routeCacheStore.addRoute(to)
3234

35+
// Set page title
36+
setPageTitle(to.meta.title)
37+
3338
if (isLogin() && !userStore.userInfo?.uid)
3439
await userStore.info()
3540

src/utils/set-page-title.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { appName } from '@/constants'
2+
3+
export default function setPageTitle(title?: string): void {
4+
window.document.title = title ? `${title} - ${appName}` : appName
5+
}

0 commit comments

Comments
 (0)