$router
相当于我们创建出来的router对象const router=createRouter();
$route
相当于我们配置的路由
const routes=[
{
path:'',
redirect:'/home'
}
]
为什么我们可以直接用this.$route或者$router?
router-view和router-link是vue注册的全局组件。
所有的组件都继承自Vue类的原型。Vue源码中用Object.defneProperty()给Vue.prototype添加了$route和$router属性,所以我们可以直接this.$route或者this.$router。$route指向的是处于活跃的那个路由。