Static GitHub Issues

[2881] ENV variables in head method

prev: The best place to initialize logger (nuxt lifecycle)
next: Server render complete hook/event

I'm looking to include og:url and twitter:url meta tags on my pages but am having trouble passing the value from nuxt.config.js.

For example:

nuxt.config.js

module.exports = {
  env: {
    host: 'http://www.mysite.com'
  }
}

index.vue

export default {
  head () {
    return {
      meta: [
        { hid: 'og:url', property: 'og:url', content: `${process.env.host}${this.$route.fullPath}` },
        { hid: 'twitter:url', property: 'twitter:url', content: `${process.env.host}${this.$route.fullPath}` }
      ]
    }
  }
}

This results in content:"undefined/about-us" for me. The only workaround I've used so far is to pass the context with asyncData, but this doesn't feel like the right solution. index.vue

export default {
  head () {
    return {
      meta: [
        { hid: 'og:url', property: 'og:url', content: `${this.ctx.host}${this.$route.fullPath}` },
        { hid: 'twitter:url', property: 'twitter:url', content: `${this.ctx.host}${this.$route.fullPath}` }
      ]
    }
  },
  asyncData (context) {
    return {
      ctx: context.env
    }
  }
}

Is there a better way to add those meta tags I'm not thinking of? Does it require middleware?

Edit: fixed code snippet. Good spot, @qm3ster

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2505">#c2505</a>)</em></sub></div>