我正在使用Nuxt SSR,并利用head函数在页面(产品页面)中生成元标记,该页面中的元标记将根据产品而动态化。
但是,如果我直接访问页面并在SEO检查器上测试页面,则不会生成元标记,因为没有元标记。如果我浏览到网站内的页面,则meta标签会完美生成。为什么会这样?
这是head函数:
const i18nSeo = this.$nuxtI18nSeo();
//@ts-ignore
const item: Item = this.item;
const setHID = (suffix: string): string => item.name + suffix;
let images = item.__images;
let image;
if (images) {
image =
images.length !== 0
? getImage(images[0].file_url)
: location.origin + '/favicon.ico';
}
return {
title: item.item_name,
meta: [
{
hid: item.name,
name: item.item_name,
content: item.description
},
{
name: 'description',
content: item.description,
hid: setHID('description')
},
{
property: 'og:title',
content: item.item_name,
hid: setHID('og-title')
},
{
property: 'og:url',
content: location.href.replace('=', '%3D'),
hid: setHID('og-url')
},
{
property: 'og:description',
content: item.description,
hid: setHID('og-description')
},
{
property: 'og:image',
content: image,
hid: setHID('og-image')
},
{
property: 'og:type',
content: 'article',
hid: setHID('og-type')
},
{
property: 'og:site_name',
content: 'Aljanoub',
hid: setHID('og-site-name')
},
...i18nSeo.meta
]
};