Is there a way to dynamically change the title of the window based on each route? I have included a meta: { title: ... }
object in each child object within the routes: []
. Here is an example:
routes: [
{
path: 'profile/:id',
name: 'Profile',
component: Profile,
meta: {
title: function (to, cb) {
const profileId = parseInt(to.params.id);
// ... do stuff ...
}
}
}
]
I am trying to call this title function using an afterEach
hook:
router.afterEach((to) => {
document.title = 'My Site';
if (to.meta && to.meta.title) {
to.meta.title(router.app, to, (result) => { document.title += ' | ' + result; });
}
});
Within the ... do stuff ...
section, I need to use a method from my mixin GetAndStore.js
called loadProfile(profileId)
. Even after adding GetAndStore
to the router's mixins and loading it globally, I am unable to access loadProfile
as it shows as undefined (this.loadProfile
). Despite trying various configurations for over an hour, I have been unsuccessful in accessing methods from the GetAndStore
mixin within this setup.
Any suggestions on what might be missing or how I can restructure to access mixin methods within
routes->element->meta->title
?