I'm using Vue Router and setting the meta
object field, which is used to set the page title and description.
Right now I set up routes like this:
[...
{
path: '/page1',
component: Page1Component,
meta: {
title: 'Title for page1'
}
}
...]
and then synchronize this with the DOM:
router.beforeEach((to, from, next) => {
document.title = to.meta.title;
next();
});
One of my routes, I want to use a query string in the title, but I can't pass a function to the meta
object. Is there a way this can be done, without defining the title in the component?
For example, what I'd want to do:
[...
{
path: '/page1',
component: Page1Component,
meta: (route) => {
title: `dynamic title is ${route.query.param}`
}
}
...]