eRouter({routes:[{path:'/home',component:Home}]});
⑤、将其路由对象传递给vue的实例,options中
⑥、留坑
<router-view></router-view>
2、命名路由:
通过a标签点击,做页面数据跳转: 使用router-link标签(一个组件,用于设置一个导航链接;切换不同html内容)
①、去哪里:
<router-link to="/beijing"> 去北京</router-link>
②、去哪里
<router-link :to="{name:'bj'}"> 去北京</router-link>
更利于维护,如果修改了path,只修改路由配置中的path,该a标签会根据修改后的值生成href属性
3、参数router-link:
在vue-router中,有两大对象被挂载到了实例this:
$route(只读,具备信息的对象)、$router(具备功能函数的对象)
查询字符串:
1、去哪里:
<router-link :to="{name:'detail',query:{id:1}}"> xxx</router-link>
2、导航(查询字符串path不能改)
{name:'detail',query:'/detail',组件}
3、去了干嘛:获取路由参数(要注意是query还是params和对应id名)
path方式:
1、去哪里:
<router-link :to="{name:'detail',params:{name:1}}"> xxx</router-link>
2、导航(path方式需要在路由规则上加上/:xxx)
{name:'detail',path:'/detail/:name',组件}
3、去了干嘛,获取路由参数(要注意是query还是params和对应name名)