mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-06 05:32:24 +03:00
don't perform client-side render if data-vue-meta-server-rendered attribute exists on html tag
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export const VUE_META_ATTRIBUTE = 'data-vue-meta'
|
||||
export const SERVER_RENDERED_ATTRIBUTE = 'data-vue-meta-server-rendered'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import updateTitleTag from './updateTitleTag'
|
||||
import updateHtmlTagAttributes from './updateHtmlTagAttributes'
|
||||
import { SERVER_RENDERED_ATTRIBUTE } from './constants'
|
||||
|
||||
/**
|
||||
* Performs client-side updates when new meta info is received
|
||||
@@ -7,10 +8,18 @@ import updateHtmlTagAttributes from './updateHtmlTagAttributes'
|
||||
* @param {Object} newInfo - the meta info to update to
|
||||
*/
|
||||
export default function updateClientMetaInfo (newInfo) {
|
||||
if (newInfo.title) {
|
||||
updateTitleTag(newInfo.title)
|
||||
}
|
||||
if (newInfo.htmlAttrs) {
|
||||
updateHtmlTagAttributes(newInfo.htmlAttrs)
|
||||
const htmlTag = document.getElementsByTagName('html')[0]
|
||||
|
||||
// if this is not a server render, then update
|
||||
if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
|
||||
if (newInfo.title) {
|
||||
updateTitleTag(newInfo.title)
|
||||
}
|
||||
|
||||
if (newInfo.htmlAttrs) {
|
||||
updateHtmlTagAttributes(newInfo.htmlAttrs)
|
||||
}
|
||||
} else {
|
||||
htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user