分为两大类
- 编程式导航
(1)params:注意(路由页面、push中的name和路由js中的name要对应上,才能实现刷新页面参数不消失)
第一步:路由js中的path要加/:type
第二步:this.$router.push({name: 'RewardBreak',params:{type:65}})
第三步:this.$route.params.type
(2)query:
第一步:this.$router.push({path: '/rewardBreak',query:{type:65}})
第二步:this.$route.query.type
- 声明式导航
<router-link :to="{name: 'RewardBreak',params:{type: 'break'}}"></router-link>
<router-link :to="{path: '/rewardBreak',query:{type: 'break'}}"></router-link>
- 总结
注:$router和$route的区别
$router是整个路由对象,有go、forward、back、push等方法可用来跳转路由
$route用于获取当前路由对象,获取传递过来的参数 。