I am using vue-meta: ^2.4.0
to populate the <head>
of my Nuxt site. Everything works as expected except for when I add non standard HTML elements. In this case, I want <nonstandard href="${process.env.SOME_VALUE_FROM_ENV}">
in the <head>
, however it never appears, even if I hardcode it with a simple value. Are non standard elements not supported?
My nuxt.config.js
is as follows:
module.exports = {
head: {
// works
htmlAttrs: {
lang: 'en'
},
// works
link: [
{ rel: 'shortcut icon', href: '/images/favicon.ico', type: 'image/ico' }
],
// works
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0' },
{ 'http-equiv': 'X-UA-Compatible', content: 'IE=Edge' }
],
// NONE OF THESE APPROACHES WORK
nonstandard: [
{ href: '${process.env.SOME_VALUE_FROM_ENV}' },
{ innerHTML: `href="${process.env.SOME_VALUE_FROM_ENV}"` }
],
innerHTML: `<nonstandard href="${process.env.SOME_VALUE_FROM_ENV}" />`,
// works
script: [
{
innerHTML: `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','xxxxxxxxxxx');
`
}
],
// works
noscript: [
{
innerHTML: `
<iframe src="https://www.googletagmanager.com/ns.html?id=xxxxxxxxxxx"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
`,
pbody: true
}
],
__dangerouslyDisableSanitizers: ['script', 'noscript', 'nonstandard'],
}
}
As suggested by @DengSihan, I was able to populate the value via a custom
app.html
which I created as a sibling of mynuxt.config.js
file.And in my
nuxt.config.js
:From this we can conclude that
vue-meta
is unable to populate the head with non-standard elements and that a customapp.html
must be used instead.