troxler / vue-headful

Set document title and meta tags with Vue.js
MIT License
229 stars 17 forks source link

Any tips when using this with vue-router? #5

Closed francoism90 closed 6 years ago

francoism90 commented 6 years ago

I'm using vuex now. :)

troxler commented 6 years ago

For the record: You could use Headful with vue-router as follows:

// router configuration
// ...
{
  path: '/',
  // ...
  meta: {
    title: 'Title',
    description: 'Description',
  }
}
// ...
import headful from 'headful';
router.beforeEach((to, from, next) => {
  headful(to.meta);
  next();
});

In that scenario, there is no need for vue-headful but only Headful.

francoism90 commented 6 years ago

@troxler And up with this:

router.beforeEach((to, from, next) => {
    const meta = _.pick(to.meta, ['title', 'description']);
    headful(meta);
    next();
});

Thanks, this is really helpful. :)