Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @bachdgvn/vue-router-meta-tags with all npm packages installed. Try it out:

var vueRouterMetaTags = require("@bachdgvn/vue-router-meta-tags")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@bachdgvn/vue-router-meta-tags v1.0.2

The simple callback to update the page title and metadata on route change for vue-router

vue-router-meta-tags

The simple callback to update the page title and metadata on route change for vue-router.

Installing

npm install @bachdgvn/vue-router-meta-tags

Usage

Open router.js, and edit your router. Make sure you placed title, metaTags for each route in routes.

import Vue from 'vue';
import Router from 'vue-router';
import VueRouterMetaTags from '@bachdgvn/vue-router-meta-tags';
import Home from './views/Home.vue';
import About from './views/About.vue';

Vue.use(Router);

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      meta: {
        title: `MyApp - Home Page`,
        metaTags: [
          {
            name: 'description',
            content: `MyApp - The home page of our example app.`,
          },
          {
            property: 'og:description',
            content: `MyApp - The home page of our example app.`,
          },
        ],
      },
    },
    {
      path: '/about',
      name: 'about',
      component: About,
      meta: {
        title: `MyApp - About us`,
        metaTags: [
          {
            name: 'description',
            content: `MyApp - The about page of our example app.`,
          },
          {
            property: 'og:description',
            content: `MyApp - The about page of our example app.`,
          },
        ],
      },
    },
  ],
});

// This callback runs before every route change, including on page load.
router.beforeEach(VueRouterMetaTags.update);

export default router;

Running the tests

npm test

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free