paste code:
I want to change document.title every time I enter a route
import Vue from "vue"
import Router from "vue-router"
Vue.use(Router)
const router = new Router({
routes: [
//
{
path: "/",
name: "index",
component: () => import("../components/index.vue"),
meta: {
title: ""
}
},
//
{
path: "/detail",
name: "Detail",
component: () => import("../components/Detail.vue"),
meta: {
title: ""
}
}
]
});
router.beforeEach((to, from, next) => {
if(to.meta.title) {
document.title = to.meta.title;
}
});
export default router
after router.beforeEach is removed, router-view appears, and then document.title does not change. After
is added back to router.beforeEach, router-view disappears and document.title changes.