DEV Community

loading...
Cover image for Nuxt.js seo ready

Nuxt.js seo ready

Tajeddine Alaoui
Full stack developer passionate about Javascript and vue.js
・1 min read

Seo is a major pillar in web development and every production project have to be optimized for seo.

We'll need to install 1 package that will assist us on seo, Will make our site stand out while sharing the link on social networks, Her's a preview.

Alt Text

You can add: image, title, descreption and theme color.

Let's start with installing nuxt-social-meta

npm i nuxt-social-meta
or
yarn add nuxt-social-meta
Enter fullscreen mode Exit fullscreen mode

Let's add meta tags on nuxt-config.js

head: {
    htmlAttrs: {
      // Add the default language of the website
      lang: 'en',
    },
    title: 'My website title',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      // Add a descreption for the website
      {
        hid: 'description',
        name: 'description',
        content: 'Descreption...',
      },
    ],
    link: [
      // Add the author
      {
        name: 'author',
        content: 'John Doe',
      },
      // Keywords related to the website
      {
        name: 'keywords',
        content: 'the best website ever',
      },
      // Favicon
      { rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' },
    ],
  },
Enter fullscreen mode Exit fullscreen mode

Now let's add the module responsible for social networks url sharing.

modules: [
    [
      'nuxt-social-meta',
      {
        title: 'website-title',
        description: 'website-descreption',
        url: 'https://website.com',
        img: '/bg.png',
        locale: 'en',
        themeColor: '#000',
      },
    ],
],
Enter fullscreen mode Exit fullscreen mode

If you want to add custom meta tags for a page then do the following

<script>
export default {
  head() {
    return {
      title: 'my website',
      meta: [
        {
          hid: 'description',
          name: 'description',
          content: 'a website descreption',
        },
      ],
    }
  },
}
</script>
Enter fullscreen mode Exit fullscreen mode

You're nuxt app is seo ready !

Discussion (0)