router和route 区别:
1、跳转到当前路由的地址:
不传参的形式: this.$router.push('/index')
直接添加路径: this.$router.push('/index?from=login')
query传参:
this.$router.push({
path:'/login', // 注意:query要用path
query:{
from:'login' // 参数名称
}
})
params传参:
this.$router.push({
name:'home-login', // 注意:params要用name
params:{
from:'login' // 参数名称
}
})
2、获取当前路由id: this.$route.params.id
4、获取当前路由地址:this.$route.path
5、获取当前hash地址:location.hash
5、获取当前路由params参数:his.$route.params.from
5、获取当前路由query参数:this.$route.query.from
5、返回上个页面:this.$router.go(-1)