import Vue from 'vue' import VueRouter from 'vue-router' Vue.use(VueRouter) var router = new VueRouter({ routes: ([ { path:'/', redirect:'/home',meta: {title:'首页'}}, { path:'/home', component: Home, name:'home',meta:{title:'首页'} } ]), }); router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } next() }) export default router哪有问题
时间: 2024-03-14 11:42:53 浏览: 236
vue.mini.js vue-router.js
这段代码看起来没有语法错误,但是缺少Home组件的引入。需要先在代码中引入Home组件,例如:
```
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from './views/Home.vue' // 引入Home组件
Vue.use(VueRouter)
var router = new VueRouter({
routes: [
{ path:'/', redirect:'/home', meta: {title:'首页'}},
{ path:'/home', component: Home, name:'home', meta:{title:'首页'} }
],
});
router.beforeEach((to, from, next) => {
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
export default router
```
另外,因为缺少Home组件的具体实现,代码中的Home组件需要根据实际情况进行修改。
阅读全文