import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/home'
import Items from '@/components/Items'
import Waterfull from '@/components/Waterfull'
Vue.use(Router)
const router = new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'home',
alias: '/home',
meta: {
title: '首页'
},
component: Home
},
{
path: '/items',
name: 'Items',
meta: {
title: 'web项目'
},
component: Items
},
{
path: '/items/Waterfull',
name: 'Waterfull',
meta: {
title: '瀑布流'
},
component: Waterfull
}
]
})
router.beforeEach(function(to,from,next){
if(to.meta.title){
document.title = to.meta.title
}else{
document.title = 'personal learn'
}
next()
})
export default router
主要通过
router.beforeEach(function(to,from,next){
if(to.meta.title){
document.title = to.meta.title
}else{
document.title = 'personal learn'
}
next()
})
进行修改;