• seo
  • vue
  • nuxt

How to define canonical URL in Nuxt.js

How to set rel=canonical to primary domain in Nuxt.js (and let search engines know to ignore duplicate content on staging server).

// layouts/default.vue 

export default {
  head() {
    return {
      link: [
        {
          rel: 'canonical',
          href: 'https://www.my-primary-domain.com' + this.$route.path
        }
      ]
    }
  }
}

Published:
Updated: