说我41行错了,不知错哪了,菜鸟教程的例子直接复制也跑不通
代码要贴全 你用的是什么浏览器
你真是vue的路由模块没安装?
1.安装
npm install vue-router --save
2.引入
import VueRouter from 'vue-router'
3.使用
Vue.use(VueRouter)
4、配置
const router = new VueRouter({
// router
routes:[
{
path:'/hello',
component:HelloWorld
}
]
})
5、注入
new Vue({
el: '#app',
router, // 注入
components: { App },
template: '<App/>'
})
6、显示路由组件
<router-view />
7、显示路由地址
this.$route.path
8、嵌套路由
routes: [
{ path: '/user/:id', component: User,
children: [
{
// 当 /user/:id/profile 匹配成功,
// UserProfile 会被渲染在 User 的 <router-view> 中
path: 'profile',
component: UserProfile
},
{
// 当 /user/:id/posts 匹配成功
// UserPosts 会被渲染在 User 的 <router-view> 中
path: 'posts',
component: UserPosts
}
]
}
]