Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: overwrite titleTemplate with undefined #218

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
reactive,
watch,
UnwrapRef,
customRef,
} from '@vue/composition-api'

import type { MetaInfo } from 'vue-meta'
Expand Down Expand Up @@ -38,7 +39,7 @@ export function createEmptyMeta(): MetaInfoMapper<Required<MetaInfo>> {
__dangerouslyDisableSanitizersByTagID: {},

title: undefined,
titleTemplate: undefined,
// titleTemplate: undefined,
htmlAttrs: {},
danielroe marked this conversation as resolved.
Show resolved Hide resolved
headAttrs: {},
bodyAttrs: {},
Expand All @@ -53,7 +54,7 @@ export function createEmptyMeta(): MetaInfoMapper<Required<MetaInfo>> {

changed: undefined,
afterNavigation: undefined,
}
} as any
}

export const getHeadOptions = (options: {
Expand Down Expand Up @@ -109,5 +110,22 @@ export const useMeta = <T extends MetaInfo>(init?: T) => {
if (process.client)
watch(Object.values(refs), vm.$meta().refresh, { immediate: true })

refs.titleTemplate = customRef((track, trigger) => {
return {
get() {
track()
return _head.titleTemplate
},
set(newValue) {
if(!_head.titleTemplate) {
Vue.set(_head, 'titleTemplate', newValue)
} else {
_head.titleTemplate = newValue
}
trigger()
}
}
})
mathe42 marked this conversation as resolved.
Show resolved Hide resolved

return refs
}