我的理解就是不同组件之间的会话,或者叫做通信
在vue中,路由通常定义了路径和需要展示的组件,即当地址栏发生变化时,会展示相应的组件
const router = new VueRouter({
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
}
]
}
]
})
顺带说一下hash模式和history模式
hash
因为hash发生变化的url都会被浏览器记录下来,从而你会发现浏览器的前进后退都可以用了,但是地址栏摆脱不了丑陋的#
由于 hash 值变化不会导致浏览器向服务器发出请求,而且 hash 改变会触发 hashchange 事件,浏览器的进后退也能对其进行控制,所以人们在 html5 的 history 出现前,基本都是使用 hash 来实现前端路由的
history
地址栏摆脱了丑陋的#,但是一旦页面刷新,需要重新向服务器请求数据,,因为刷新是实实在在地去请求服务器的,不玩虚的