I want to set the page title to a different value for each page.
In regular Vue.js, I have done the following:
import router from './router'
import { store } from './store/store';
router.beforeEach((to, from, next) => {
store.mutations.setRoute(to);
document.title = store.getters.pageTitle;
next();
}
How would I get that effect in nuxt?
That is, on both initial page load and when changing pages, I want the browser tab's title to change. For instance, from "My App - About" to "My App - Profile".
from nuxt docs, in each
pages
component you can define the head function that returns the title of page i.e.I found a way to do this, but I don't know if it is the "right" way. I use the
mounted()
function indefault.vue
for the initial page load and thetransition
property innuxt.config.js
for each page change. So, indefault.vue
:And in
nuxt.config.js
: