Skip to content

Commit

Permalink
feat: Set document title via route meta (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleeWa committed Nov 8, 2024
1 parent 0820b7b commit 2648fc4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const appName = 'vue3-vant-mobile'
export const appDescription = 'An mobile web apps template based on the Vue 3 ecosystem'
5 changes: 5 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import 'nprogress/nprogress.css'
import type { EnhancedRouteLocation } from './types'
import useRouteCacheStore from '@/stores/modules/routeCache'
import { useUserStore } from '@/stores'

import { isLogin } from '@/utils/auth'
import setPageTitle from '@/utils/set-page-title'

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

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

// Set page title
setPageTitle(to.meta.title)

if (isLogin() && !userStore.userInfo?.uid)
await userStore.info()

Expand Down
5 changes: 5 additions & 0 deletions src/utils/set-page-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { appName } from '@/constants'

export default function setPageTitle(title?: string): void {
window.document.title = title ? `${title} - ${appName}` : appName
}

0 comments on commit 2648fc4

Please sign in to comment.